Easy Steps to Install GitLab on Ubuntu 22.04

In this guide, we want to teach you How To Install GitLab on Ubuntu 22.04. GitLab is a web-based Git repository that provides free open and private repositories, issue-following capabilities, and wikis. It is a complete DevOps platform that enables professionals to perform all the tasks in a project—from project planning and source code management to monitoring and security. Additionally, it allows teams to collaborate and build better software. 

Steps To Install and Configure GitLab on Ubuntu 22.04

To Install GitLab on Ubuntu 22.04, 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 22.04.

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

Install GitLab on Ubuntu 22.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 the GitLab Installation Script

First, switch to your /tmp directory:

cd /tmp

Then, use the following command to download the GitLab installation script on Ubuntu 22.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 22.04:

sudo apt install gitlab-ce

Configure Firewall Rules

At this point, you need to ensure that your firewall rules are permissive enough to allow web traffic. We assumed that you have enabled the 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 22.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'] = ['olivia@example.com']
...

When you are done, save and close the file.

Now use the command below to reconfigure GitLab on Ubuntu 22.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 have learned to Install GitLab on Ubuntu 22.04. Now 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 - Install GitLab on Ubuntu 22.04

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 22.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 GitLab on Ubuntu 22.04. Also, you have learned to configure and access the GitLab dashboard from the web interface. Hope you enjoy it.

You may like these articles:

How To Install the Latest Git on AlmaLinux 8

How To Install the Latest Git on Ubuntu 22.04

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!