How To Install GitLab on Ubuntu 20.04

In this guide, we intend to teach you How To Install and Configure GitLab on Ubuntu 20.04.

Gitlab is a service that provides remote access to Git repositories. In addition to hosting your code, the services provide additional features designed to help manage the software development lifecycle. These additional features include managing the sharing of code between different people, bug tracking, wiki space, and other tools for ‘social coding’.

Steps To Install and Configure GitLab on Ubuntu 20.04

To complete this guide, you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our guide on Initial Server Setup with Ubuntu 20.04.

Also, you need a domain name that is pointed to your server’s IP address.

Install GitLab on Ubunutu 20.04

First, you need to update your local package index with the following command:

sudo apt update

Then, use the following command to install GitLab dependencies:

sudo apt install ca-certificates curl openssh-server postfix tzdata perl

For the postfix installation, select Internet Site when prompted. On the next screen, enter your server’s domain name to configure how the system will send mail.

Download GitLab Installation Script on Ubuntu 20.04

First, switch to your /tmp directory:

cd /tmp

Then, use the following command to download the GitLab installation script on Ubuntu 20.04:

curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh

Next, run the installer script by using the command below:

sudo bash /tmp/script.deb.sh

When you are done, you will get the following output:

Output
The repository is setup! You can now install packages.

Now you can install the GitLab application on Ubuntu 20.04:

sudo apt install gitlab-ce
Output

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.



     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/


Thank you for installing GitLab!

Configure Firewall Rules for Gitlab

At this point, you need to ensure that your firewall rules are permissive enough to allow web traffic. We assumed that you have enabled UFW firewall from the requirements.

To adjust the firewall rules, run the commands below:

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

To apply the new rules, reload the firewall:

sudo ufw reload

Configure GitLab on Ubuntu 20.04

At this point, you need to update the GitLab configuration file. To do this, open the file with your favorite text editor, here we use vi:

sudo vi /etc/gitlab/gitlab.rb

Find the external_url configuration line and update it to your domain and make sure to change http to https to automatically redirect users to the site protected by the Let’s Encrypt certificate.

...
external_url 'https://your_domain'
...

Also, find the line below and uncomment it by removing the “#” and setting your email address:

...
letsencrypt['contact_emails'] = ['[email protected]']
...

When you are done, save and close the file.

Reconfigure Gitlab

Now use the command below to reconfigure GitLab on Ubuntu 20.04:

sudo gitlab-ctl reconfigure

This will initialize GitLab using the information it can find about your server. The process will also configure a Let’s Encrypt certificate for your domain.

This will take some time to complete.

When you are done, you will get the following output:

Output
gitlab Reconfigured!

Access GitLab Web Interface

At this point, you can continue your GitLab configuration from the Web interface. To do this, type your domain name in your web browser as shown below:

https://your_domain

You will see the GitLab Community Edition Login page.

Note: GitLab generates an initial secure password for you. It is stored in a folder that you can access as an administrative sudo user:

sudo vi /etc/gitlab/initial_root_password

You should see something similar to this:

Password: your-initial-root-password

Now from your GitLab login page enter root as the username and your initial password as your password and click Sign in.

Gitlab login screen

You will be signed in to the GitLab application and taken to a landing page that prompts you to begin adding projects.

Gitlab dashboard

From here you can update your password, adjust your profile settings, change your account name, add an SSH key to your account, etc.

Renew Let’s Encrypt Certificates for GitLab on Ubuntu 20.04

By default, GitLab has a scheduled task set up to renew Let’s Encrypt certificates after midnight every fourth day, with the exact minute based on your external_url.

You can change these settings by modifying the GitLab configuration file:

sudo vi /etc/gitlab/gitlab.rb

Then, find the following lines in the file and remove the # and update it with the following:

letsencrypt['auto_renew'] = true
letsencrypt['auto_renew_hour'] = "12"
letsencrypt['auto_renew_minute'] = "30"
letsencrypt['auto_renew_day_of_month'] = "*/7"
...

This will renew your certificates every 7th day at 12:30. You can change it to your desired date.

Also, you can disable auto-renewal by setting the letsencrypt[‘auto_renew’] to false:

...
letsencrypt['auto_renew'] = false
...

When you are done, save and close the file.

Conclusion

At this point, you have learned to Install and Configure Gitlab on Ubuntu 20.04.

Hope you enjoy it.

You may be like these articles:

How To Install Latest Git on Debian 11

Install OpenLiteSpeed on Ubuntu 20.04

Set up MySQL and Workbench on Ubuntu 20.04

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular