How to Install GitLab on Ubuntu 16.04

How to Install GitLab on Ubuntu 16.04

One of the alternatives for Github is the Gitlab git repository manager. In this tutorial, we are going to show you how to install GitLab (Community Edition) on Ubuntu 16.04.
Gitlab offers outstanding features like repository branching, merging, file locking and tagging, time tracking and many more, so you can take full advantage of it.
Gitlab has self-hosted and paid version (Enterprise Edition) and self-hosted and free (Community Edition). In this article, we will install the Community Edition by using the ‘omnibus’ package offered by official Gitlab.

Prerequisites

We will assume that you have a VPS with freshly installed Ubuntu 16.04. Other then the Ubuntu for recommended hardware requirements you will need:

2 cores
4GB of RAM
Root privileges

For more information about hardware requirements, you can check the official Gitlab page.

Install Required Packages

Before we begin the installation of GitLab, we need to be sure that Ubuntu already has the necessary packages installed to run GitLab. To install the necessary dependencies, we need to execute the command below:

sudo apt update
sudo apt install curl openssh-server ca-certificates

Also, we need to install Postfix MTA for notifications.

sudo apt install postfix

A configuration screen may appear during Postfix installation. Choose the “Internet Site” and press Enter. After this, need to provide a mail server name or IP address to configure how the system will send mail. You can proceed if additional screens appear and accept the default values.

Install and configure Gitlab packages

Now that dependencies are set, we can proceed with installing GitLab. This is a direct process that uses an installation script named ‘omnibus’ to configure your system with GitLab repositories.

We will add the repository for the GitLab package by running the following command:

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

Next step is to install the GitLab package. In the following command, you need to change the URL from http://your_domain.com to the domain you will use to access the GitLab instance. The domain you will set it will be configured automatically by the script we are using. After the installation, there is an additional configuration for setting up the HTTPS protocol.

sudo EXTERNAL_URL="http://your_domain.com" apt install gitlab-ee

If the upper instruction was carefully followed, now you have installed GitLab CE on your Ubuntu 16.04. server.

First browsing on your domain

When you access your_domain.com for the first time at your favorite browser, you will be redirected to the reset password screen. Of course in this screen, you need to enter your admin password and when you will finish with this, you will be redirected to the login screen again so you can log in for the first time. The username will be set by default as root, so you can use it when you try to log in.

Generate Let’s encrypt SSL certificates

In this section, we will install the free Let’s Encrypt SSL certificate for our newly installed GitLab. In order to generate a Let’s Encrypt Certificate, we will use the letsencrypt command tool.

To install the letsencrypt command-line tool on Ubuntu 16.04, run the following command:

sudo apt install letsencrypt

Using the below command you can generate a new Let’s Encrypt SSL certificate for your domain.

sudo letsencrypt certonly --standalone -d your_domain.com

After executing this command you need to enter your email address. Next step you can type ‘A’ so you Agree with the Terms of Service. After accepting on ToS there is one more step which is optional. You can choose ‘Y’ or ‘N’ and wait for the script to finish the installation of the SSL certificate for your_domain.com.

Please note: in some situations installation of the Let’s Encrypt SSL certificate may be not successful. So, you need to stop the application using sudo systemctl stop gitlab-runsvdir.service and re-run the letsencrypt tool. Once the script will finish you can start the GitLab application using sudo systemctl start gitlab-runsvdir.service.

Enable HTTPS for GitLab

Since we have generated an SSL certificate with Let’s Encrypt, in this step we will enable HTTPS connection and forward from all HTTP to HTTPS.

We will configure GitLab by editing the configuration file ‘gitlab.rb’ as an example shown below:

sudo nano /etc/gitlab/gitlab.rb

Change the HTTP to HTTPS at external_url:

external_url 'https://your_domain.com'

Modify and uncomment this configuration as the following example:

letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['[email protected]']
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/letsencrypt/live/your_domain.com/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/your_domain.com/privkey.pem"

After completing the modifications, save the changes and exit the nano.

Please note: You need to change your_domain.com with the GitLab domain that you used to configure.

The last step is to execute the following command and apply the GitLab configuration:

sudo gitlab-ctl reconfigure

In summary, we installed GitLab CE on Ubuntu 16.04. Also, we installed Let’s Encrypt SSL and configure GitLab to work on HTTPS. For more information about GitLab feel free to look at their official website documentation at https://docs.gitlab.com/


Install GitLab on Ubuntu 16.04 You don’t have to install GitLab on your Ubuntu 16.04 VPS if you use our server administration services, in which case you can simply ask our expert Linux admins to install GitLab for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, on How to Install GitLab on Ubuntu 16.04, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *