Ubuntu

Install GitLab on Ubuntu 22.04

GitLab is a web-based Git repository that acts as a version control system. A Version Control System (VCS) software tracks and maintain the source code changes in a collaborative environment. Like GitHub and Bitbucket, GitLab also allows you to access the Git repositories remotely.

GitLab can be used to share the code and necessities of a program throughout the development lifecycle of that program. One of the primary advantages of GitLab is that you can manage the Git repositories as per your requirement such as keeping the information public/private.

This article provides a step-by-step installation of GitLab on Ubuntu 22.04. Additionally, you will also learn to configure GitLab on Ubuntu 22.04.

Prerequisites

You need to install various tools such as curl, OpenSSH server, etc., to install and use GitLab on Ubuntu 22.04.

Firstly, update the system’s packages list by issuing the following command:

$ sudo apt update

Text Description automatically generated

Now, install the prerequisites by issuing the following command:

$ sudo apt install tzdata curl ca-certificates openssh-server

Text Description automatically generated
Text Description automatically generated

How to install GitLab on Ubuntu 22.04

Although GitLab is not available on the official repository of Ubuntu 22.04. However, we have an alternate method to get GitLab on Ubuntu 22.04. For a better understanding, we have divided the installation into various steps:

Step 1: At the time of this write-up, the Gitlab repository for Ubuntu 22.04 is not available. Here, we will configure the Gitlab repository for Focal-Fossa (Ubuntu 20.04) on Jammy Jellyfish (Ubuntu 22.04).

Firstly, you must import the GPG key by issuing the following command:

$ gpg_key_url="https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey"

curl -fsSL $gpg_key_url| sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/gitlab.gpg

Now, add the Gitlab repository of Ubuntu 20.04 inside the sources.list.d file of Ubuntu 22.04.

$ sudo tee /etc/apt/sources.list.d/gitlab_gitlab-ce.list<<EOF

deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main

deb-src https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main

EOF

Text Description automatically generated

Step 2: After doing so, update the core libraries of Ubuntu 22.04 as follows:

$ sudo apt update

Text Description automatically generated

Now, execute the following command to install GitLab on Ubuntu 22.04:

$ sudo apt install gitlab-ce

Text Description automatically generated
Text Description automatically generated

The above command has installed the GitLab community edition on Ubuntu 22.04.

Verify the installation with the help of the following command:

$ sudo gitlab-rake gitlab:env:info

Text Description automatically generated

How to configure GitLab on Ubuntu 22.04

Although the installation of the GitLab has been completed successfully. However, you cannot use GitLab without proper configuration. The following steps would lead you to configure the GitLab before using it:

Step 1: GitLab listens to port 80 (http) and port 443 (https). Firstly, allow both ports on the firewall by using the following commands:

$ sudo ufw allow https

$ sudo ufw allow http

$ sudo ufw allow ssh

Graphical user interface Description automatically generated

Reload the firewall settings to adapt to the above changes:

$ sudo ufw reload

A picture containing text Description automatically generated

Step 2: Check the web address where the Gitlab web interface will be accessible:

$ sudo nano /etc/gitlab/gitlab.rb

Text Description automatically generated

The web address can be found in the line that starts with “external_url” as shown in the above image.

Now, reconfigure the GitLab with the help of the following command:

$ sudo gitlab-ctl reconfigure

Text Description automatically generated

Step 3: Lastly, execute the following command to start the GitLab-server:

$ sudo gitlab-ctl start

Text Description automatically generated

You can also get the status of the GitLab services as follows:

$ sudo gitlab-ctl status

Text Description automatically generated

Moreover, the below-mentioned command allows you to restart the Gitlab web-services:

$ sudo gitlab-ctl start

Text Description automatically generated

How to remove GitLab from Ubuntu 22.04

GitLab is a very useful tool to develop software in a collaborative manner. If you are not using the GitLab services anymore then you can remove it from Ubuntu 22.04 by issuing the following command:

$ sudo apt remove gitlab-ce

Text Description automatically generated

You can also remove the GitLab repository from the apt list as follows:

$ sudo rm /etc/apt/sources.list.d/gitlab_gitlab-ce.list

Conclusion

GitLab is the widely used Git repository to track and manage the changes made to the source code of a program. Gitlab is exercised as a Version Control System (VCS) by organizations like NASA, IBM, Sony, SpaceX, Alibaba, and many more. This article provides the installation procedure of GitLab on Ubuntu 22.04. Apart from installation, you have learned the configuration, usage, and removal of GitLab on Ubuntu 22.04.

About the author

Adnan Shabbir