Signup/Sign In
PUBLISHED ON: JANUARY 20, 2022

How to Install and Configure GitLab on Ubuntu 18.04

GitLab is a web-based open-source Git repository manager developed in Ruby integrating wiki, issue management, code review, monitoring, and continuous integration and deployment. It allows developers to build, evaluate, and launch their projects.

There are three main versions of GitLab available, Community Edition (CE), Enterprise Edition (EE), and a GitLab-hosted version.

GitLab is the number one alternative if you wish to shift away from GitHub. It can import projects and problems from numerous sources including GitHub, which simplifies the migration process hassle-free. The GitLab UI is well-designed, clear, straightforward, and close to GitHub’s in terms of user experience and functionality.
There are numerous methods to install GitLab based on the necessary use case. This guide covers the steps required for installing and configuring GitLab (CE) on an Ubuntu 18.04 machine using the Omnibus packages.

Prerequisites

This guide assumes that you have a fresh Ubuntu 18.04 installation. According to the GitLab requirements page, it is advised to utilize a server with:

  • at least 4GB of RAM capacity.

  • 2 CPU cores.
  • at least 2GB of swap space.
  • (optional) Domain or subdomain linking to the server IP address.

For an extra layer of protection, it is advisable to set up a simple firewall. You may follow the instructions in our How To Set Up a Firewall with UFW on Ubuntu 18.04 tutorial.
Before proceeding with the instruction, ensure sure you are logged in as a user with sudo rights.

Installing Required Dependencies

Refresh the local package index and install the dependencies using the following commands:

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


In order for GitLab to be able to send notification emails, you can either install and use Postfix or use some transactional mail service such as SendGrid, MailChimp, MailGun, or SES in which case you can skip the following step and configure [GitLab SMTP settings] (https://docs.gitlab.com/omnibus/settings/smtp.html ) after the installation is completed.

Run the following instructions to install Postfix on your Ubuntu server:

debconf-set-selections <<< "postfix postfix/mailname string $(hostname -f)"
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
sudo apt install postfix

For more thorough information on how to establish your own mail server read this series.

Installing GitLab

GitLab installation is a relatively plain clear procedure. We will install the GitLab CE package using the apt package manager.

Start by adding the GitLab repository to your system sources list using the following curl command :

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

Once the repository is enabled install the GitLab package by performing the following command.

sudo apt install gitlab-ce 

The installation procedure may take a while and after a successful installation, you will see the following output:

Thank you for installing GitLab!

Adjusting the Firewall Rules

The instructions about setting up a simple firewall is given in the requirements section. To be able to access the GitLab interface we need to open ports 80 and 443:

sudo ufw allow OpenSSH
sudo ufw allow http
sudo ufw allow https

To make sure that the relevant ports are open you may verify the status of the firewall with:

sudo ufw status

Output

Status: active

To                         Action      From
--                         ------      ----
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
OpenSSH                    ALLOW       Anywhere
80/tcp (v6)                ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)
OpenSSH (v6)               ALLOW       Anywhere (v6)

Set the GitLab URL

Before using the GitLab web interface we need to configure the URL on which GitLab will be available. Open Gitlab’s configuration file and make the following changes:

sudo nano /etc/gitlab/gitlab.rb

Near the top of the configuration file, you will find a line beginning with an external URL. Change the value to match your domain/subdomain or IP address. If you have a domain use HTTP and if you want to access the GitLab interface via your server IP address use HTTP.

/etc/gitlab/gitlab.rb \sexternal url 'https://gitlab.example.com


Next look for “Let’s Encrypt integration”, uncomment the line beginning with letsencrypt['enable'] and change it to true. Optionally if you wish to get emails from Let’s Encrypt about your domain uncomment the line beginning with letsencrypt['contact emails'] and enter your email address.

If you specify the external URL to an IP address then don’t activate Let’s Encrypt integration.

/etc/gitlab/gitlab.rb
letsencrypt
['enable'] = true \sletsencrypt['contact emails'] = ['admin@example.com'] #

This should be an array of email addresses to add as contacts

Finally, save and close the file and execute the following command to reconfigure Gitlab:

sudo gitlab-ctl reconfigure 

The program will modify your GitLab settings and produce a free Let’s Encrypt SSL certificate.

Configure GitLab with the Web Interface

Now that you have specified the GitLab URL you may start with the basic configuration using the GitLab web interface.

Launch your web browser and go to:

https://your gitlab domain or server IP.com



About the author:
Pradeep has expertise in Linux, Go, Nginx, Apache, CyberSecurity, AppSec and various other technical areas. He has contributed to numerous publications and websites, providing his readers with insightful and informative content.