How to Install GitLab on Ubuntu – Easy Way

GitLab is an open-core DevOps platform that provides a complete end-to-end solution for software development, delivery, and lifecycle management. Ubuntu is one of the best systems for hosting GitLab because it provides an officially supported, stable, secure, and high-performance environment. Furthermore, its LTS reliability, strong package ecosystem, and security infrastructure make it ideal for self-managed enterprise GitLab deployments.

Installing GitLab On Ubuntu

GitLab on Debian-based Linux systems, such as Ubuntu, can be installed only via its bash script, which adds its repository to the apt package installer. There are two versions for GitLab: the enterprise and the community edition. Before installing GitLab, there are some prerequisites, like the installation of curl, OpenSSH, and a firewall are necessary:

sudo apt install openssh-server

Installing OpenSSH on Ubuntu to install GitLab on Ubuntu

Download and execute the GitLab bash file using the Curl Utility by using the command below:

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

Downloading GitLab bash file on Ubuntu

Now install GitLab on Ubuntu by using the apt package installer. After adding the repository, the apt packages list is updated automatically:

sudo apt install gitlab-ce -y

Installing GitLab community edition on Ubuntu via its bash file

Alternatively, the custom GitLab URL can also be added while installing GitLab on Ubuntu simultaneously for accessing it from the browser:

sudo EXTERNAL_URL="https://gitlab.example.com" apt install gitlab-ce

Setting up GitLab on Ubuntu

To run GitLab on Ubuntu, several configurations need to be done, like creating a username and password, allowing it through the firewall, adding an email, or creating a custom URL. Navigate to the GitLab directory in the etc folder and execute the following command:

sudo gitlab-ctl reconfigure

Configuring the GitLab configuration file on Ubuntu

This will take some time, and once done, there will be a message of GitLab reconfigured as in the image below:

GitLab configuration completed on Ubuntu

Alternatively, the domain for accessing GitLab via browser can also be added manually in its configuration file:

sudo nano gitlab.rb

Editing GitLab configuration file on Ubuntu

Search for external_url in the GitLab configuration file and edit the line with the desired custom URL for logging into the GitLab account:

external_url 'https://gitlab.[custom _URL]

Adding external_url in GitLab configuration file on Ubuntu

Next, for creating the username, add the email as well, and for that, search for letsencrypt in the GitLab configuration file:

letsencrypt['contact_emails'] = []

Adding email address for username in GitLab configuration file on Ubuntu

Now run the reconfiguration command after saving the changes, and as a result, a temporary password will be generated, valid for 24 hours:

Reconfiguring GitLab Configuration file after adding data manually on Ubuntu

To see the temporary password, open the initial_root_password file in the GitLab directory in Ubuntu:

sudo nano initial_root_password

Reading temporary password in initial_root_password file of GitLab on Ubuntu

Copy the password and close the file:

Reading temporary password in initial_root_password file of GitLab on Ubuntu

Next, allow HTTP, HTTPS, and OpenSSH from the Ubuntu firewall by executing the following commands:

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

Allowing HTTP, HTTPS,OpenSSH through Ubuntu firewall for GitLab

After adding the rules in the firewall on Ubuntu, check their status via executing the following command:

sudo ufw status

Verifying the rules added in Ubuntu firewall for GitLab

Now access GitLab on Ubuntu either via the external URL added via the configuration file or by the default system IP address. In case of an external URL, use the email and the password from the GitLab configuration file, and in the other case, click on Register now:

Signing in to GitLab account oin Ubuntu

Fill up all the necessary fields with the correct data and then click on Continue:

Registering new account on GitLab on ubuntu

After creating the account, there might be an error in account activation due to the approval of the administrator, so in that case, log in via the admin account:

Pending admin approval error on GitLab signup

Since by default, a root user is created for GitLab on Ubuntu, execute the below command to reset the root password:

sudo gitlab-rake "gitlab:password:reset"

Resetting root password of gitLab on Ubuntu

Next, log in via the same password to login:

Logging in to GitLab on Ubuntu

Conclusion

GitLab is a complete DevSecOps ecosystem that unifies code collaboration, CI/CD automation, security testing, and deployment within one interface. To install GitLab on Ubuntu, download its bash file and use the apt package installer. Furthermore, after installation, execute the reconfigure command to access it via browser on Ubuntu.

Index
Scroll to Top