GitLab is a software tool designed to store and manage Git repositories. It facilitates and accelerates the process of collaborative coding, testing, and deployment.
This list of features is not exhaustive; it represents just the essential components necessary to understand the importance of using this software in project activities.
This article will provide a detailed guide on how to install GitLab on Ubuntu and configure it afterward.
Below is a list of requirements sufficient for installing GitLab on a server.
First, you will need a server located either on a personal computer or in the cloud. According to GitLab's documentation requirements, the server should be equipped with:
Second, you will need a domain name that points to the server. In this guide, we will use example.com.
The first step is to install the software required for GitLab. You can download it from the Ubuntu repositories.
Perform a package update:
sudo apt-get update
Next, install the necessary dependencies:
sudo apt-get install -y curl openssh-server ca-certificates tzdata perl
The next thing to install on the server is Postfix (or Sendmail), which serves as a mechanism for sending notifications to email:
sudo apt-get install -y postfix
During the installation, you need to select Internet Site in the pop-up window.
Next, specify the server's domain — in our case, it will be example.com
.
Now we can start installing GitLab. Let's download the script:
cd /tmp
curl -LO https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh
To check the functionality of this script, enter the command:
sudo less /tmp/script.deb.sh
If everything is satisfactory, you can proceed directly to running the script:
sudo bash /tmp/script.deb.sh
Once the script has finished running, you can start the GitLab installation:
sudo apt install gitlab-ce
First, you need to check which network protocols are allowed. To see the status of the firewall, enter the command:
sudo ufw status
In the output, we see that traffic is currently allowed only for the SSH protocol.
Status: active
To Action From
– ------- ----
OpenSSH ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
In addition to SSH, you need to allow the HTTP and HTTPS traffic.
sudo ufw allow http
sudo ufw allow https
After making these changes, check the firewall status again to make sure all changes have taken effect.
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
80/tcp ALLOW Anywhere
443/tcp ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
443/tcp (v6) ALLOW Anywhere (v6)
Before starting GitLab, it is important to edit the configuration in the gitlab.rb
file using the nano
editor:
sudo nano /etc/gitlab/gitlab.rb
In the opened file, find the external_url
line and change the domain name to example.com. You will have a different name. We will also switch to a more secure encryption protocol — HTTPS.
##! EXTERNAL_URL will be used to populate/replace this value.
##! On AWS EC2 instances, we also attempt to fetch the public hostname/IP
##! address from AWS. For more details, see:
##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
external_url 'https://example.com'
## Roles for multi-instance GitLab
##! The default is to have no roles enabled, which results in GitLab running as an all-in-one instance.
Next, find the Let's Encrypt integration
section and the # letsencrypt['contact_emails']
line. Uncomment the line and insert the email address into the brackets.
# Let's Encrypt integration
################################################################################
# letsencrypt['enable'] = nil
letsencrypt['contact_emails'] = [[email protected]] # This should be an array of email addresses to add as contacts
# letsencrypt['group'] = 'root'
# letsencrypt['key_size'] = 2048
This is necessary for sending notifications in case of issues with the domain.
Save your changes (CTRL+O) and exit the file (CTRL+X). To apply all changes, run the reconfiguration:
sudo gitlab-ctl reconfigure
This will pass all the server information to the application and reconfigure Let's Encrypt for the domain.
Enter your domain name in your browser's address bar to access your GitLab instance.
Upon your first visit, a welcome page will appear, prompting you to set a password for your account. After entering and confirming a strong password, you will be redirected to the authentication window.
To log into the administrator account, you need to fill in the following fields:
Username: root
Password: the password you set earlier.
Once logged in, the home page will open, where the user can create their first project and get started.
The new GitLab user will have standard user settings applied. To change them, go to the Settings tab in the upper right corner of the window in the dropdown menu.
In the Profile section, you can update your information.
Important changes at this stage will be the name and email address. The name will be visible to other project members, while the email is necessary for receiving notifications from the service. To link the new email, you need to confirm it via the email sent by the service.
To apply the changes, click the Update profile settings button at the bottom of the screen.
Navigate to the Account section in the settings menu on the left. Here, you should change the automatically assigned name to something more unique, as illustrated in the image below. This will provide additional security for the account in the event of attempted hacks.
Additionally, in this section, the user can enable two-factor authentication.
To interact with Git and GitLab, you need to generate and attach a public key in the settings.
Start by generating the keys:
ssh-keygen
During the key generation process, the system will prompt you to specify a custom storage location for the key pair and set a passphrase for added security. To skip these steps, simply press Enter.
Once the key generation is complete, copy the public key and paste it into the interface, adding a brief description.
To open the public key, use the following command:
cat ~/.ssh/id_rsa.pub
After copying the key to the required section, click the "Add key" button.
To create your first project in GitLab:
Now you can upload project files, add users for collaboration, or delete the project if necessary.
This article has provided a step-by-step guide to installing GitLab on Ubuntu 22.04. After completing all the steps, you can deploy your first project in the system and start working with it.