Install & Configure Gitlab on Ubuntu 20.04 LTS

GitLab is a free and open-source web-based code repository for collaborative software development for DevOps, written in Ruby and Go programming languages. GitLab’s main motto is “Bring velocity with confidence, security without sacrifice, and visibility into DevOps success.” It is quite a popular alternative to GitHub providing wiki, issue-tracking, and continuous integration and deployment pipeline features, using an open-source license, developed by GitLab Inc.

In the following tutorial, you will learn how to install and configure Gitlab on Ubuntu 20.04 LTS Focal Fossa Desktop or Server, along with how to get started by logging in with root so you can begin setting up GitLab to your liking or for your team’s requirements.

Prerequisites

  • Recommended OS: Ubuntu 20.04.
  • User account: A user account with sudo or root access.

Update Operating System

Update your Ubuntu operating system to make sure all existing packages are up to date:

sudo apt update && sudo apt upgrade -y

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@ubuntu ~]$ sudo whoami
root

To set up an existing or new sudo account, visit our tutorial on How to Add a User to Sudoers on Ubuntu.

To use the root account, use the following command with the root password to log in.

su

The tutorial will utilize the terminal interface, which can be found in the show applications menu.

Example:

Install & Configure Gitlab on Ubuntu 20.04 LTS

Install Dependencies for GitLab

Before you install GitLab on your system, you will need to install the dependencies for it so that you can install and operate GitLab.

Open your terminal and execute the following command:

sudo apt install curl ca-certificates apt-transport-https gnupg2 -y

Create & Import GitLab Repository

By default, GitLab does not come packaged in Ubuntu’s default repositories, and this means you will need to create one manually. However, GitLab has created a handy APT script for you to download and execute to aid you in this task.

Download the GitLab APT script using the curl command:

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

Example output from the script:

Install & Configure Gitlab on Ubuntu 20.04 LTS

Now run the apt update command to verify and sync the new repository.

sudo apt update

Install Gitlab

The next part of the tutorial is to install GitLab, and you should have already used the apt update command to sync the newly created and modified repository. Now execute the install command using the following:

sudo apt install gitlab-ce

Example output and dependencies to be installed along GitLab:

Install & Configure Gitlab on Ubuntu 20.04 LTS

Type Y, then press the ENTER KEY to proceed with the installation.

Note that the installation size is 2.5GB, so slow Internet connections could wait a while to complete the download and installation.

Once the installation is complete, you should get the following output in your terminal.

Example:

Install & Configure Gitlab on Ubuntu 20.04 LTS

How to Configure GitLab

With GitLab installed, you can now configure SSL, the domain name or subdomain name passwords, and much more. The tutorial will go over the basic setup options that should be done. However, you can do alternative settings to those listed below.

First, open the “gitlab.rb” configuration file using any text editor:

sudo nano nano /etc/gitlab/gitlab.rb

The first setting will be setting the domain, navigating down to line 36, and finding the following.

Example only:

external_url 'https://gitlab.linuxcapable.com'

Change this to your subdomain name or domain.

Example:

Install & Configure Gitlab on Ubuntu 20.04 LTS

Next, set up TLS/SSL with Let’s Encrypt, which starts at 2297.

By default, all settings are commented out with “#.” You will need to uncomment the following lines.

 letsencrypt['enable'] = true
 letsencrypt['contact_emails'] = ['youremail@yourdomain.com']
 letsencrypt['auto_renew'] = true
 letsencrypt['auto_renew_hour'] = 4
 letsencrypt['auto_renew_day_of_month'] = "*/4"
 letsencrypt['auto_renew_log_directory'] = '/var/log/gitlab/lets-encrypt'

Example:

Install & Configure Gitlab on Ubuntu 20.04 LTS

Once done, CTRL+O then exits the file with CTRL+X.

Now run the reconfigure command as follows.

sudo gitlab-ctl reconfigure

In the end, you will receive the following message in your terminal.

Example:

Install & Configure Gitlab on Ubuntu 20.04 LTS

To view the root (GitLab) password, run the following command.

sudo cat /etc/gitlab/initial_root_password

Example output:

Install & Configure Gitlab on Ubuntu 20.04 LTS

As above, you can see the password is “XPOmq6lNgfp8ECQ+0LyGxrhFiW+HZ1BBh1pK7bAAyfw=” and that this file will be automatically deleted in 24 hours.

How to Access GitLab

Now that the backend is set, it is time to log in and see your GitLab.

First, open up the domain path where GitLab was assigned in the configuration file.

Example:

https://gitlab.example.com

Next, sign in using the username “root” and the password you received, which in the tutorial case was “SGGg/WQ9+N1JdgouIbPftla+Kt8Qcyr+HL5oJfRbBmM=”.

Example:

Install & Configure Gitlab on Ubuntu 20.04 LTS

You are successfully logged in as the root account, and you will hit the default landing page.

Example:

Install & Configure Gitlab on Ubuntu 20.04 LTS

From here, you can proceed to set up and configure GitLab to suit your requirements or your team. One of the first things you should do is go to the admin section and configure the security, such as 2FA, changing root passwords, and much more before adding any team members. This can all be found by clicking on the Menu > Admin in the top left-hand corner of the page.

Example:

Create Cronjob for GitLab Auto Backup

By default, there are no backups created or configured. This should be set using a cronjob, and the frequency set a value that suits your availability of resources and frequency of GitLab changes.

First, open your crontab.

sudo crontab -e

Next, add the following example and modify the time to suit your needs. If you are unsure of the timing, then visit crontab.guru.

00 */3 * * *  gitlab-rake gitlab:backup:create

The above creates a backup every 3 hours exactly.

Example:

Install & Configure Gitlab on Ubuntu 20.04 LTS

Once done, CTRL+O then exits the file with CTRL+X.

Alternatively, you can run the task manually by executing the following command.

sudo gitlab-rake gitlab:backup:create

Example output:

Install & Configure Gitlab on Ubuntu 20.04 LTS

As above, you will get a message advising the backup is done, along with a message that sensitive files are not included due to security risks.

Comments and Conclusion

In the following tutorial, you have learned how to install GitLab on Ubuntu 20.04 LTS, set up TLS/SSL with Lets Encrypt, and create a backup cron job. Overall, self-hosting GitLab can be significant than relying on a third party if privacy is an important concern and can make development easier and quicker.



Follow LinuxCapable.com!

Like to get automatic updates? Follow us on one of our social media accounts!