Install GitLab on your VPS to host a repository (Tutorial)

Why install GitLab on your VPS?

GitLab is an open source application that offers a graphical user interface (GUI) to help manage Git repositories. It includes lots of features, such as issue tracking and easy pull requests and merges.

If you don’t want to pay for GitHub’s or Bitbucket’s paid features, or if you want to maintain full control over your codebase, then a self-hosted GitLab installation is a great option.

Today, we’ll walk you through how to install GitLab on your VPS running Ubuntu, Debian or CentOs.

Prerequisites for GitLab installation:

Step 1: Installing dependencies

To get ready to install GitLab on your VPS, you need to install some dependencies.

Luckily, they’re available in default repositories:

Ubuntu 16.04/18.04, Debian 8/9/10

$ sudo apt install curl openssh-server ca-certificates postfix

Centos 7

$ sudo yum install curl policycoreutils openssh-server openssh-clients
$ sudo systemctl enable sshd
$ sudo systemctl start sshd
$ sudo yum install postfix
$ sudo systemctl enable postfix
$ sudo systemctl start postfix
$ sudo firewall-cmd --permanent --add-service=http
$ sudo systemctl reload firewalld

Step 2: Installing GitLab on VPS

First, you need to add the GitLab repository, and then install the package.

Note: We recommend that you check all scripts you’re executing as the sudo user before you execute them. You can find GitLab’s install script here.

Ubuntu 16.04/18.04, Debian 8/9/10

$ curl -s | sudo bash

$ sudo apt install gitlab-ce

CentOS 7

$ curl -sS | sudo bash

$ sudo yum install gitlab-ce

This operation might take a bit to complete.

When it’s done, you’ll see the following output:

*.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********

     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ 
  / /_/ / / /_/ /___/ /_/ / /_/ /

gitlab: Thank you for installing GitLab!
gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND:

sudo gitlab-ctl reconfigure

Step 3: Run and configure GitLab

You’ve now installed GitLab on your VPS, so let’s fire it up and make sure it’s running smoothly.

See that command above? Give it a whirl.

$ sudo gitlab-ctl reconfigure

You’ll see quite a bit of output as the script operates.

If you need to make any changes to the external URL, for example, or any of the other configuration options, you can edit the gitlab.rb script and then re-run the configuration.

$ sudo nano /etc/gitlab/gitlab.rb
$ sudo gitlab-ctl reconfigure

IMPORTANT: If you followed our previous tutorial on installing a LEMP stack, you will need to configure GitLab to work with your existing nginx installation. GitLab has detailed instructions on how to configure the connection in their documentation.

Step 4: Log into GitLab for the first time

Once you’ve made any changes to GitLab’s configuration and it’s up and running without errors, you can direct your web browser to the default external URL, or the one you chose.

If you see the following page, you’ve successfully installed GitLab!

GitLab Success

Provide a password for the administrator account when prompted.

Then enter the password you choose, and then you’ll be directed to a login screen.

GitLab Login

The administrator username is root by default. Enter that plus the password you just created, and you’ll be ready to start managing your Git repositories directly on your own VPS!



Oct 4, 2019: Updated to include Ubuntu 18.04, Debian 9, Debian 10 & CentOs 7.