How to Install GitLab on Ubuntu 22.04 Step-by-Step

In this blog post, we will explain how to install GitLab on Ubuntu 22.04 step-by-step. Gitlab comes with Enterprise edition (Gitlab EE) and Community edition (Gitlab CE). In this post , we will cover the community edition installation.

GitLab, an open-source platform, provides a robust and feature-rich solution for managing repositories, issues, CI/CD pipelines, and much more. If you’re an Ubuntu 22.04 user and want to set up your own GitLab instance to streamline your DevOps workflow, you’re in the right place.

Prerequisites

  • A virtual or dedicated server running Ubuntu 22.04 with SSH access.
  • Static Hostname (gitlab.linuxtechi.net)
  • Sudo User with admin rights
  • 2 GB RAM or more
  • 2 vCPUs or more
  • Internet Connectivity

1) Update System Packages

Let’s begin by updating the package lists and upgrading any existing packages to their latest versions.

$ sudo apt update
$ sudo apt upgrade -y

Reboot the system after applying updates,

$ sudo reboot

2) Install Dependencies

GitLab requires some dependencies to function correctly. Install them using the following commands:

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

During the postfix installation, a configuration window will appear. Choose “Internet Site” and enter your server’s hostname as the mail server name. This will allow GitLab to send email notifications.

Choose-Internet-Site-Postfix-Gitlab-Installation-Ubuntu,

Choose “Internet Site” and then slect OK.

System-Hostname-Postfix-Gitlab-Ubuntu

Check system’s hostname and choose OK.

3) Add GitLab Apt Repository

Now, we’ll add the GitLab repository, run the following curl command. It will automatically detect your Ubuntu version and will set the repository accordingly.

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

Add-GitLab-CE-Apt-Repository-Ubuntu

4) Install Gitlab on Ubuntu 22.04

Run the beneath command to install and configure gitlab-ce  on your ubuntu system automatically, replace the server’s hostname as your setup,

$ sudo EXTERNAL_URL="http://gitlab.linuxtechi.net" apt install gitlab-ce

Once the above the command is executed successfully, we will get output something like below,

Apt-Install-Gitlab-ce-Ubuntu

Gitlab-Successful-Installlation-Message-Ubuntu

Output above confirms that GitLab has been installed successfully. User name for gitlab web interface is root and password is stored at “/etc/gitlab/initial_root_password

Note : If OS firewall is enabled on your ubuntu system, then allow 80 and 443 ports.

$ sudo ufw allow http
$ sudo ufw allow https

5) Access GitLab Web Interface

With GitLab installed and configured, open your web browser and enter your server’s IP address or hostname.

http://<Server-IP-Address-or-Hostname>

  • User Name: root
  • Password : <<Get Password from /etc/gitlab/initial_root_password>>

GitLab-Login-Page-Post-Installation-Ubuntu

click on “Sign in”

GitLab-Web-Interface-Ubuntu

Great, above confirms that we have successfully login to Gitlab Web interface.

As of now our GitLab Server is working on http (80) protocol, if you want to enable https for your GitLab, then refer the below steps,

6) Secure GitLab Web Interface

For added security, you can configure HTTPS for your GitLab instance using self-signed certificate or Let’s Encrypt. We can use Let’s encrypt only for public domain whose A recorded available on internet. But in our case, we are using a private domain, so we will be using self-signed certificate to secure GitLab.

Now, let’s create following folder and generate self-sign certificates using openssl command

$ sudo mkdir -p /etc/gitlab/ssl
$ sudo chmod 755 /etc/gitlab/ssl

Generate the private key using following openssl command,

$ sudo openssl genrsa -des3 -out /etc/gitlab/ssl/gitlab.linuxtechi.net.key 2048

Enter the passphrase and and remember it

Create the CSR using below command,

$ sudo openssl req -new -key /etc/gitlab/ssl/gitlab.linuxtechi.net.key -out /etc/gitlab/ssl/gitlab.linuxtechi.net.csr

Generate-CSR-Self-Sign-Cert-Gitlab

Remove Passphrase from the key, execute the following commands one after the another

$ sudo cp -v /etc/gitlab/ssl/gitlab.linuxtechi.net.{key,original}
$ sudo openssl rsa -in /etc/gitlab/ssl/gitlab.linuxtechi.net.original -out /etc/gitlab/ssl/gitlab.linuxtechi.net.key
$ sudo rm -v /etc/gitlab/ssl/gitlab.linuxtechi.net.original

Create the Certificate file

$ sudo openssl x509 -req -days 1460 -in /etc/gitlab/ssl/gitlab.linuxtechi.net.csr -signkey /etc/gitlab/ssl/gitlab.linuxtechi.net.key -out /etc/gitlab/ssl/gitlab.linuxtechi.net.crt

Remove the CSR file using below rm command,

$ sudo rm -v /etc/gitlab/ssl/gitlab.linuxtechi.net.csr

Set the permissions on key and certificate file

$ sudo chmod 600 /etc/gitlab/ssl/gitlab.linuxtechi.net.key
$ sudo chmod 600 /etc/gitlab/ssl/gitlab.linuxtechi.net.crt

All the important configuration for Gitlab server is controlled by the file “/etc/gitlab/gitlab.rb” So edit this file,  search “external_url” and add the “https://gitlab.linuxtechi.net”

$ sudo vi /etc/gitlab/gitlab.rb
----------------------------------------------------------
external_url 'https://gitlab.linuxtechi.net'
----------------------------------------------------------

Save and exit the file, reconfigure gitlab using beneath command so that it’s web interface start working https.

$ sudo gitlab-ctl reconfigure

Gitlab-reconfigured-Ubuntu

Once above command is executed successfully, then your GitLab interface should be accessible over https protocol, In my case url will be: https://gitlab.linuxtechi.net/

When you access it first time, it will say something like your connection is not secure, click on “Accept the Risk and Continue”

Gitlab-Web-Interface-over-Https-Ubuntu

Conclusion

Congratulations! You’ve successfully installed GitLab on your Ubuntu 22.04 system. With GitLab up and running, you can now create repositories, collaborate with your team, and enhance your development workflow through GitLab’s impressive features. Enjoy seamless version control, continuous integration, and more, all under your control!

Share Now!

2 thoughts on “How to Install GitLab on Ubuntu 22.04 Step-by-Step”

  1. After running steps 1 & 2 above then running step 3 I get the following error
    sudo apt install gitlab-ce returns Unable to locate package gitlab-ce

    Reply
    • Hi Gerald,

      It seems like gitlab ce repository is not configured properly on your system that’s why you are getting the error.

      To Fix this issue, please try to enable the repo using the step2 and then run “apt-get update” and after that try to install gitlab-ce packages.

      Reply

Leave a Comment