How to Install Gitlab on an Ubuntu Server

Install Gitlab on Ubuntu

Gitlab is a self-hosted Git management tool, similar to popular options like Github and Bitbucket. Instead of hosting your projects on someone else’s service, though, you run the server and have complete control over your own projects. You’re not at the mercy of changes imposed by the provider.

Gitlab also lets you include your repositories under your own domain or subdomain. It makes it easier for people to find your project that way, in some cases, and it keeps things more consistent. You’re also in control of what gets updated and when.

There’s also the matter of Github’s acquisition by Microsoft. If you’re just using it as a tool and don’t care much about open-source philosophy, that probably won’t matter too much to you. However, if you’re maintaining or contributing to an open-source project regularly, chances are you have some pretty strong feelings about Microsoft. Gitlab is a great way to bypass that situation entirely.

Install the Dependencies

Start by installing a couple dependencies on your Ubuntu server. Gitlab needs them to get set up.

sudo apt install curl openssh-server ca-certificates postfix

Postfix will prompt you along the way what kind of installation to do. Gitlab is a website, so use that option.

Get the Gitlab Repository

Add Gitlab Repository

The Gitlab team maintains their own repositories for Ubuntu. They also provide a convenient script that sets up those repositories for you. Use cURL to download the script and run it.

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

It’ll take a few seconds for the script to download and set everything up.

Install Gitlab

You don’t need to update Apt this time. The script already did that for you. The only thing you need to do is install the Gitlab package.

sudo apt install gitlab-ce

Gitlab Installed

This process will take a while. Gitlab is actually a complex Ruby on Rails web application. The package installation will not only download everything necessary to set up that application, it’ll also configure it all for you.

Reconfigure Gitlab

Once Gitlab is installed, you’re going to need to tell it to finish its configuration.

sudo gitlab-ctl reconfigure

That’ll take a couple of minutes, too. The default configuration is good for most situations. If you want to change something, though, it’s all accessible, and you can change it at any time. Actually, there’s one thing you should change now if you’re using Gitlab on a web-facing server.

Open “/etc/gitlab/gitlab.rb.” This is the main configuration for Gitlab. Find the following option, and set it equal to the domain name you want to use.

external_url "http://gitlab.example.com"

Reconfigure Gitlab again for the change to stick.

Using Gitlab

Gitlab is a web application just like Github or Bitbucket. Its interface and controls should feel familiar to anyone who has used either of those services. Open your browser and navigate to the address you set for your server. If you’re just running it locally, “localhost” will do.

Create Your Admin Account For Gitlab

When you arrive, you’ll be greeted with a page asking for you to set a password for your admin account. The default account is “root.” After you set your password, you can sign in.

Gitlab Dashboard

After you sign in, you’ll get your first look at the Gitlab dashboard. It’s very clean and visually simplistic. You can create new projects, add users, and access just about any functionality that you’ll need from here.

Add user to Gitlab

Before you start using Gitlab regularly, you’re going to want to create a regular user account for yourself. It’s probably not the best to use the admin user for everything. Your regular user can do everything you can do on another Git host, so it won’t feel too different or limited. Reserve your admin account for actual administration and management.

Now, you can go ahead and start adding and configuring your own projects. Connect your existing projects, and import your SSH keys like you normally would. Since you’re in control now, keep an eye out for new updates and releases from Gitlab, and also be sure to keep your server updated, too.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Nick Congleton

Nick is a freelance tech. journalist, Linux enthusiast, and a long time PC gamer.