How to Install GitLab on Ubuntu 20.04

GitLab is a web-based tool which provides a Git repository manager and DevOps lifecycle tool. It is a feature rich tool that offers issue tracking, continuous integration, deployment pipeline.

GitLab comes with two distributions: the Enterprise Edition and the Community Edition. GitLab community edition is opensource. Enterprise edition comes with additional features.

In this tutorial we learn how to install GitLab Community Edition on Ubuntu 20.04.

There are mainly two ways to install GitLab on Ubuntu.

  • Using the GitLab package repository
  • Manually download and install the .deb package

Prerequisites

  • Ubuntu 20.04 node
  • Minimum of 4GB RAM - (8 GB is recommended)
  • Minimum of 2 CPU cores - (4 cores recommended)
  • Minimum available disk space of 10GB
  • Access to DNS to setup domain to point GitLab instance.

Method 1: Install Gitlab CE using package repository

Installing using package repository is the recommended way of installing GitLab.

First update Ubuntu, type:

$ sudo apt update

Now install all the required package dependencies:

$ sudo apt-get install -y curl openssh-server ca-certificates

Install Postfix you need want to GitLab to send notifications (this is optional):

$ sudo apt-get install -y postfix

Then configure postfix as a send-only smtp server.

To add the GitLab package repository, type:

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

Now you can install the GitLab package (this package also know as Omnibus):

$ sudo apt-get install gitlab-ce

Method 2: Manually download and Install the .deb package

To download GitLab Community Edition .deb package, go to packages.gitlab.com and choose the one that matches to your Ubuntu machine.

Click on the package, that will redirect to a page which contains link to download the package.

$ wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/focal/gitlab-ce_13.11.7-ce.0_amd64.deb/download.deb

To install the downloaded GitLab package, type:

sudo dpkg -i gitlab-ce_13.11.7-ce.0_amd64.deb 

Setup GitLab web interface

Lets go ahead and setup the GitLab web interface.

GitLab important files are:

  • /opt/gitlab contains application code for GitLab and its dependencies
  • /var/opt/gitlab contains data and config files that gilab-ctl-reconfigure writes to
  • /var/log/gitlab contains all the log data generated by GitLab
  • /etc/gitlab contains config files for GitLab

Make sure the port 80 and 433 is allowed on the firewall:

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

To configure the external URL , open the configuration file:

$ sudo vim  /etc/gitlab/gitlab.rb 

Set your domain name for the external_url in the configuration script and save the file.

external_url = "http://websitefortesting.com/"

Make sure to put your domain name for the external_url in the configuration script and save the file.

Configure GitLab Server with Lets Encrypt SSL

Its possible to enable SSL either using Lets Encrypt, self signed certificate or from trusted vendors.

To enable Lets Encrypt SSL, set the variable letsencrypt[enable] to true.

letsencrypt[enable] = 'true'

To configure Gitlab to renew Lets Encrypt SSL certificate automatically on a regular interval:

# Enable the auto renew feature
letsencrypt['auto_renew'] = true
 
# This example renews every 5th day at 1:30 AM
letsencrypt['auto_renew_hour'] = "1"
letsencrypt['auto_renew_minute'] = "30"
letsencrypt['auto_renew_day_of_month'] = "*/5"

Run gitlab-ctl reconfigure command every time after you make any changes to /etc/gitlab/gitlab.rb config file.

 $ sudo gitlab-ctl reconfigure 

Now to start GitLab server, type:

$ sudo gitlab-ctl start

Navigate to the URL in your browser to setup GitLab web interface. It will prompt you to setup a new password.

Initial password setup

The default username is root. Login to the account with the password you created.

GitLab home page

To verify the GitLab version from GUI - click on the icon in the upper right showing ? and from the dropdown menu select Help.

You can also check GitLab version using command line, type:

$ sudo gitlab-rake gitlab:env:info

The version which we installed is GitLab Community Edition 13.11.17.

By default GitLab allows user new signup, for secure access its advised to disable it. You can disable it from the web console - Menu > Admin -> Uncheck the Sign-up enabled box.

You can follow the next steps after installing GitLab from the official documentation.

Conclusion

In this tutorial we learned how to install GitLab community edition on an Ubuntu 20.04.

If you have any feedback and suggestion please comment below.

Leave a Comment