Git has become the default version control system for much of the open source world. While Git hosting services like Github and Bitbucket are good and work well, they leave you dependent on those services for everything, including crucial factors like uptime and security. Aside from that, neither of those services are open source. Thankfully, an alternative exists in the form of Gitlab.

Gitlab is an open source Git repository service written in Ruby on Rails that can either be self-hosted, or purchased as a service. Hosting Gitlab is fairly easy, especially since it comes in a per-configured "Omnibus" package.
Ubuntu 16.04 running MPD Gitlab

Installation

The Gitlab developers have made it relatively easy to install with a package repository and install scripts, so the first thing to do is update Ubuntu and install the required dependencies.
$ sudo apt-get install curl openssh-server ca-certificates postfix
Next, get the Gitlab install script with curl and run it. The script will add the Gitlab repository to your system for easy installs and updates in the future. Once the script is finished, use Apt to install the Gitlab Community Edition package.
# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
# sudo apt-get install gitlab-ce
The install shouldn’t take that long, and when it completes, Gitlab needs to be configured. The Gitlab “Omnibus” package contains all of the software needed to get Gitlab running, including the Ruby on Rails project, a database, and a web server. The configuration utility will automatically configure all of that for your system. Don’t worry if you wan something specific. That can be changed later.
# sudo gitlab-ctl reconfigure
The configuration will take several minutes, since it needs to go through a ton of different things to get Gitlab working. The good news is, once it’s done, you really don’t have to configure anything, if you don’t want to. Also, because Ubuntu is a Debian based distribution, Gitlab will start as soon as the configuration finishes.

Using Gitlab

First Run

Gitlab login screen
By default, the Gitlab web interface will be accessible on localhost through the browser. This can be changed with configuration later on. Once you get there, you will be prompted to create a new password and log in. The default user is root, so the password that you would be setting is the root password for the Gitlab install. Once you do that, you can sign out and make your user account. Once you create the account, you will be signed in to your "Welcome" screen.

From the “Welcome” screen, you can create a new project repository. When you start a project, you will be taken to a simple screen that allows you to name the project and set the level of access that others will have to it.
Gitlab repository creation screen

SSH Keys

In order to securely connect to your Gitlab repository, you need to use SSH keys, If you already have one that you would like to use, skip down a bit. If not, you can create them easily with one command. To create an SSH key, type the following linux command in the terminal.
$ ssh-keygen -t rsa -C "This email address is being protected from spambots. You need JavaScript enabled to view it.
	"
The “user” portion would be your user name, either on your local machine or the server, and the “domain.com” part would either be the name of your computer or the domain of the server. However you’d prefer to do it will work fine. Now, the next line will show the key that you just generated.
$ cat ~/.ssh/id_rsa.pub
You should see a long string of characters. From that file, copy the line that begins with ssh-rsa. Back in the browser, pull down the menu, and navigate to "Profile Settings". From there, select "SSH Keys” from the menu across the top. Paste your key into the box marked, "Key" and give it a name before saving it. After that, your repository should be set up to use like any other web-based Git hosting service.
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in: