Read in 6 minutes
How To Install and Configure GitLab on Ubuntu 18.04
GitLab is a web-based open source Git repository manager written in Ruby including wiki, issue management, code review, monitoring and continuous integration and deployment. It enables developers to create, review, and deploy their projects. There are three different editions of GitLab available, Community Edition (CE), Enterprise Edition (EE), and a GitLab-hosted version.
There are several ways to install GitLab depending on the required use case. This guide covers the steps necessary for installing and configuring GitLab (CE) on a Ubuntu 18.04 system using the Omnibus packages.
This tutorial assumes that you have a fresh Ubuntu 18.04 Installation. According to the GitLab requirements page it is recommend to use a server with:
- at least 4GB of RAM memory
- 2 cores
- at least 2GB of swap space.
- (optional) Domain or subdomain pointing to the server IP address.
For additional layer of security it is recommended to set up a basic firewall. You can follow the steps in our How To Set Up a Firewall with UFW on Ubuntu 18.04 guide.
Before starting with the tutorial, make sure you are logged in as a user with sudo privileges.
Installing Required Dependencies
Refresh the local package index and install the dependencies with the following commands:
sudo apt update sudo apt install curl openssh-server ca-certificates
In order for GitLab to be able to send notification emails we can either install and use Postfix or use some transactional mail service such as SendGrid, MailChimp, MailGun or SES in which case you can skip the following step and configure GitLab SMTP settings after the installation is completed.
To install Postfix type:
debconf-set-selections <<< "postfix postfix/mailname string $(hostname -f)" debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'" sudo apt install postfix
GitLab installation is pretty straight forward process. We will install the GitLab CE package using the
apt package manager.
First we need to add the GitLab repository to our sources list:
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
Once the repository is enabled we can install the GitLab package by running the following command.
sudo apt install gitlab-ce
The installation process may take a while and after a successful installation, you will see the following output:
Thank you for installing GitLab!
Adjusting the Firewall Rules
The guide about setting up a basic firewall is linked in the prerequisites section. To be able to access the GitLab interface we need to open ports
443, to do that type:
sudo ufw allow OpenSSH sudo ufw allow http sudo ufw allow https
To be sure that the required ports are open you can check the status of the firewall with:
sudo ufw status
Status: active To Action From -- ------ ---- 80/tcp ALLOW Anywhere 443/tcp ALLOW Anywhere OpenSSH ALLOW Anywhere 80/tcp (v6) ALLOW Anywhere (v6) 443/tcp (v6) ALLOW Anywhere (v6) OpenSSH (v6) ALLOW Anywhere (v6)
Set the GitLab URL
Before accessing the GitLab web interface we need to set the URL on which GitLab will be reachable. Open Gitlab’s configuration file and make the following changes:
sudo vim /etc/gitlab/gitlab.rb
Near the top of the configuration file you will see a line starting with
external_url. Change the value to match your domain/subdomain or IP address. If you have domain use
https and if you want to access the GitLab interface through you server IP address use
Next search for “Let’s Encrypt integration” uncomment the line starting with
letsencrypt['enable'] and set it to true. Optionally if you want to receive emails from Let’s Encrypt concerning your domain uncomment the line starting with
letsencrypt['contact_emails'] and add your email address. If you set the
external_url to an IP address then do not enable the following options.
letsencrypt['enable'] = true letsencrypt['contact_emails'] = ['[email protected]'] # This should be an array of email addresses to add as contacts
Finally save and close the file and run the following command to reconfigure Gitlab:
sudo gitlab-ctl reconfigure
The command will reconfigure your GitLab settings and generate a free Let’s encrypt SSL certificate.
Configure GitLab through the Web Interface
Now that we have configured GitLab URL we can start with the initial configuration through the GitLab web interface.
Open your browser of choice and navigate to:
https://your_gitlab_domain.com # or http://server_IP
Set the administrative account password
Since this is the first time we are accessing the web interface we will be prompted to set the password for the administrative account.
Enter a secure password and click on the
Change your password button when you are finished.
You will be redirected to the login page:
The default administrative account username is
root. Later in this tutorial we will show you how to change the username.
- Username: root
- Password: [the password you have set]
Once you enter the login credentials and click the
Sign in button you will taken to the GitLab Welcome page.
Edit your User Profile
The first thing that you will want to do is to edit your user profile. Click on the user avatar (upper-right corner) and from the drop down menu, select
Here you can change your Name, Email and other profile information and settings. Make the changes according to your liking.
Once you are done click on the
Update Profile settings button and shortly you will receive a confirmation email to the address you provided. To confirm your account follow the instructions provided in the email.
Changing your Username
To access the Profile page, click on the
Account link from the left-hand vertical navigation menu.
As you already know the default username of the first administrative account is
root. To change it just type your new username and click on the
Update username button.
On this screen you can also enable two-factor authentication.
The next time you will login to your GitLab dashboard you will need to enter the new username.
Adding an SSH Key
To be able to push your local git changes to the GitLab server you to add your SSH public key to your GitLab account.
If you already have an SSH key pair created on your local system you can display the public key by typing:
The output should look something like the following:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDd/mnMzHwjUzK8g3ldfsfRpJuC16mhWamaXRk8ySQrD/dzpbRLfDnZsLxCzRoq+ZzFHGwcQlJergtergdHGRrO8FE5jl3IWRRp+mP12qYw== [email protected]
In case the command above prints
No such file or directory it means that you do not have a SSH key pair generated on your machine.
To generate a new SSH key pair, you use the following command:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Copy the output from the cat command and go back to the GitLab’s web interface. Click
SSH Keys from the left-hand vertical navigation menu to access the SSH Keys configuration page.
Key textarea paste the public key you previously copied from your local machine, set a descriptive title and click on the
Add key button:
Now you should be able to push and pull your project changes from your local computer without having to provide your GitLab account credentials.
This tutorial walked you through the installation and configuration of GitLab on Ubuntu 18.04. You also learned how to edit your profile settings, how to change the username and add an SSH key. You can now create your first project and start using your GitLab.
If you have questions feel free to leave a comment below.