How to install and configure GitLab CE and GitLab Runner on Ubuntu Server

How to install and configure GitLab CE and GitLab Runner on Ubuntu Server

In this guide, I will show you how to install GitLab Community Edition (CE) and GitLab Runner on an Ubuntu server.

GitLab is one of the most widely used platforms for code versioning, Git repository management, and Continuous Integration/Continuous Delivery (CI/CD). In this guide, I will show you how to install GitLab Community Edition (CE) and GitLab Runner on an Ubuntu server.

Before you begin, make sure you have:

  • An Ubuntu server with root access or a user with sudo privileges.
  • At least 4GB of RAM for GitLab.
  • A domain name or public IP address for accessing GitLab.

Installing GitLab CE

It is important to make sure your system is up to date before proceeding with the installation. Run the following commands:


sudo apt update
sudo apt dist-upgrade -y

GitLab requires some dependencies to work properly. Let's install them:


sudo apt install -y curl ca-certificates tzdata perl

Let's add the official GitLab repository using curl to download the package and apt to install it:


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

After adding the repository, we can proceed with the installation:


sudo apt install gitlab-ce

Once installed, we need to configure GitLab for our domain or IP. Edit the main configuration file:


sudo nano /etc/gitlab/gitlab.rb

Find the line external_url and set it to your domain or IP:


external_url 'https://example.com'

Save and close the file. Then, run the following command to apply the configuration:


sudo gitlab-ctl reconfigure

This command will take a few minutes and will automatically configure GitLab CE.

Once the configuration is complete, you can log in to GitLab by visiting the domain or IP configured in the previous step using a browser. The first time you log in, you will be asked to set a password for the root user.

Installing GitLab Runner

GitLab Runner is the tool that GitLab uses to run CI/CD jobs. Now we will see how to install it.

First, add the GitLab Runner repository:


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

Install GitLab Runner with the following command:


sudo apt install gitlab-runner

After installation, we need to register the Runner with our GitLab project. First, log in to your GitLab interface, go to "Settings" of your project and then to "CI/CD" > "Runners". You will find a registration token. Use that token to register the Runner by running:


sudo gitlab-runner register

During the registration process, you will be asked to provide:

  • GitLab URL (e.g. https://example.com)
  • Registration token
  • Runner description (you can name it anything you like)
  • Runner tags (you can leave blank if you are unsure)
  • Runner (choose shell for a basic installation)

Once registered, start and enable GitLab Runner to start automatically at system boot:


sudo gitlab-runner start
sudo systemctl enable gitlab-runner

Conclusion

We have seen how to install and configure GitLab CE and GitLab Runner on Ubuntu Server. With GitLab CE, you can manage your repositories and implement efficient CI/CD pipelines thanks to GitLab Runner. You can now start working on your projects with a powerful and versatile tool like GitLab.