Install GitLab on Ubuntu

GitLab is an open-source web-based application used for managing Git-repositories for collaborative development. Its main purpose is managing multiple software development projects and its files among members of a team or an organization. It can also provide issue and time tracking, reviews, branching, and many more development-related features that use Git functionality.

GitLab is maintained and developed using Ruby on Rails by GitLab Inc. It is licensed under an open source (MIT) license, as well as including some proprietary licenses. Our GitLab Hosting is fully managed and is perfect for this purpose.

In this article, we will show you how to install GitLab on Ubuntu 18.04.

Prerequisites:

Make sure your server meets the following minimum requirements:

  • 2 CPU Cores
  • 8 GB of RAM
  • A VPS running Ubuntu 18.04 or later
  • Domain name pointed to your server IP address – we will be using git.rosehostingtest.com as an example.
  • Full root access

You can learn more about server requirements here.

Install Updates and Dependencies

Log in to your server via SSH:

ssh username@server_ip

Before starting with the GitLab installation, it is a good idea to update the system packages to their latest versions.

sudo apt-get update
sudo apt-get upgrade

Ensure that the required dependencies are installed by running the following command:

sudo apt-get install curl openssh-server ca-certificates postfix software-properties-common -y

Installing Let’s Encrypt SSL and Configuring a DHPARAM Certificate

It is best to use GitLab through HTTPS as this will make the connection to important project files secure.

To begin, install the required packages from Certbot – a program that automates SSL/TLS certificate installation using Let’s Encrypt Free SSL:

sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot 

Next is to generate an SSL certificate for our domain. First, we make sure that port 80 will not be in use by Apache:

sudo systemctl stop apache2
sudo systemctl disable apache2

After that, we can now proceed to generate Let’s Encrypt SSL certificates for our domain:

sudo certbot certonly --standalone -d git.rosehostingtest.com

If the process is a success, you should see the following message:

Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/git.rosehostingtest.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/git.rosehostingtest.com/privkey.pem

To generate the DHPARAM certificate, use the following commands:

sudo mkdir -p /etc/gitlab/ssl/
sudo openssl dhparam -out /etc/gitlab/ssl/dhparams.pem 4096

It is required to change the file permissions of the certificate.

sudo chmod 600 /etc/gitlab/ssl/dhparams.pem

Now that we have generated an SSL and DHPARAM certificate for our domain, we can now proceed with installing GitLab.

Installing GitLab Community Edition (CE)

There are two self-hosted editions for GitLab – GitLab CE (Community Edition) and GiLlab EE (Enterprise Edition). The Community Edition is free to use, while the Enterprise Edition is paid – it comes with additional features. In this tutorial, we will install the Community Edition.

Add the GitLab repository:

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

After adding the repository, we can now proceed to download the GitLab CE package:

sudo apt install gitlab-ce -y

Configuring GitLab

After a successful installation, we will need to configure our URL to be used by our application.

sudo nano /etc/gitlab/gitlab.rb

Now modify the “external_url” variable to utilize your domain.

external_url 'https://git.rosehostingtest.com'

After that, we will need to set up security measures for our GitLab Server. Paste the following under the “#GitLab Nginx” section to override some settings.

nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/letsencrypt/live/git.rosehostingtest.com/fullchain.pem"
nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/git.rosehostingtest.com/privkey.pem"
nginx['ssl_dhparam'] = "/etc/gitlab/ssl/dhparams.pem"

We are then required to run a command to reconfigure GitLab settings:

sudo gitlab-ctl reconfigure

If the reconfiguration is a success, you should see the following message:

gitlab Reconfigured!

Setting up a Firewall

Ubuntu’s built-in firewall must be configured to allow three protocols: SSH, HTTP, and HTTPS.

To allow the three protocols, execute the following:

sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https

To verify the firewall settings:

sudo ufw status

Enable the new settings:

sudo ufw enable

Post-Installation GitLab Steps

After successfully installing GitLab, you can now visit your GitLab application by visiting your domain name in a web browser. At first, it will prompt for a password change.

To log in, supply the following credentials:

Username: root

Password: <the password you set>

Managing the GitLab Service

To start GitLab:

sudo gitlab-ctl start

To stop GitLab:

sudo gitlab-ctl stop

To restart GitLab:

sudo gitlab-ctl restart

To start, stop, or restart an individual component:

sudo gitlab-ctl <start, stop, restart> <component>

That’s it! You now have a working GitLab CE server on Ubuntu 18.04.


Of course, you don’t have to install GitLab on Ubuntu 18.04 if you have Ubuntu VPS Hosting with us. You can simply ask our support team to install GitLab on Ubuntu 18.04 for you. They are available 24/7 and will be able to help you with the installation.

PS. If you enjoyed reading this blog post on how to install GitLab on Ubuntu 18.04, feel free to share it on social networks using the shortcuts below, or simply leave a comment in the comments section. Thanks.