How to Install GitLab Runner on Ubuntu 24.04

In this blog post, we will show you how install GitLab runner on Ubuntu 24.04. If you have already set up GitLab on Ubuntu 24.04 (as covered in our previous tutorial), this post will help you extend your GitLab capabilities by adding a GitLab Runner for CI/CD pipelines

GitLab is a versatile, open-source platform designed for hosting and managing code repositories. Packed with powerful features, it provides a central hub for collaborative software development. As a great alternative to GitHub, GitLab is an excellent choice for managing large DevOps projects. Its robust CI/CD tools empower development teams to automate, build, test their code, and effortlessly track issues, streamlining the entire software development lifecycle.

Gitlab runner is a lightweight agent designed to execute jobs defined in your gitlab-ci.yml file directly on your local machine or server. This file outlines the various stages of your CI/CD pipeline, including building, testing, and deployment. The GitLab Runner takes care of running these tasks and seamlessly reports the results back to your GitLab instance, making it an essential tool for streamlining your automation workflows.

1) Update Apt Repository Index

To get started, log in to your server and refresh the local APT cache. This ensures you’re pulling the latest package information before proceeding.

$ sudo apt update

Once the cache is updated, head over to the next step.

2) Download GitLab Runner Installer Script

GitLab isn’t included in Ubuntu’s default repositories. Instead, GitLab provides its own installation script to make the setup process quick and easy. Simply download and run the GitLab Runner installer script as shown below.

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

Download-Gitlab-Runner-Script-Ubuntu

The installation script takes care of everything for you—it updates the local package cache, installs the necessary dependencies, and adds the GitLab Runner repository to the /etc/apt/sources.list.d directory. This repository is where your system will pull packages from to install GitLab Runner.

3) Install GitLab Runner on Ubuntu 24.04

Now that the repository is set up, your system knows where to fetch the GitLab Runner package. To install GitLab Runner, simply use the APT package manager with the following command.

$ sudo apt install gitlab-runner

Install Gitlab Runner On Ubuntu 24.04

To confirm the version of GitLab runner installed, run the command:

$ sudo gitlab-runner -version

Check-Gitlab-Runner-Version-Ubuntu

From the output, you can see that we have installed the latest version which is GitLab Runner 16.6.0.

4) Verify GitLab Runner’s Status

By default, GitLab Runner auto-starts once installed, and you can verify this as shown.

$ sudo gitlab-runner status

Gitlab-Runner-Service-Status-Ubuntu

If for some reason the service is not running, you can start it as shown.

$ sudo gitlab-runner start

You can also set it to start on system boot by enabling the service.

$ sudo gitlab-runner enable

5) How To Register GitLab Runner on GitLab

After installing GitLab Runner, the next step is to register it with your GitLab account. This process connects your runner to your GitLab projects, enabling it to execute CI/CD tasks seamlessly.

Before you begin, ensure you have a GitLab account, an existing project, and a Project Runner set up.

To register your GitLab Runner, navigate to your project in GitLab. In this example, we’ll use a project called Epiphany. Simply click on your project in the left sidebar to get started.

Choose-Epiphany-Option-Gitlab-UI

Next, head over to ‘Settings‘  –>  ‘CI/CD‘.

Choose-CI-CD-Option-Gitlab-UI

In case you don’t have a runner, here’s how to create it. In the ‘Runners‘ section, click ‘Expand‘.

Select-Runners-Expand-Gitlab-UI

Next, click ‘New Project Runner‘ to create a project runner

New-Project-Runners-Gitlab-UI

Be sure to fill in all the necessary fields and click ‘Create Runner

Maximum-Job-Timeout-Gitlab-Runners

With the runner already created, copy the token value which will be used to register the GitLab Runner from the command line.

Copy-Token-for-Gitlab-Runner-Registration

Back on the command line, run the following command to register the runner where token-number is the token value that you copied.

$ sudo gitlab-runner register token-number

The command walks you through a series of prompts:

First, you will be required to provide the GitLab URL instance: Type https://gitlab.com  and hit ENTER.

Next, you will be prompted for the registration token. Key in the same token value you copied and press ENTER.

Next, provide an executor. If you are unsure of what to provide, simply go with ‘Shell’.

Finally, you will get the notification that the Runner has successfully been registered.

The configuration – together with the authentication token – will be saved in the /etc/gitlab-runner/config configuration file.

Gitlab-Runner-Register-Commamd-Ubuntu

Conclusion

That’s a wrap for today’s guide! We have covered how to install GitLab Runner on Ubuntu 24.04 and walked you through the process of registering your GitLab Runner with GitLab. If you have any questions or feedback, don’t hesitate to drop them in the comments below – we would love to hear from you!

Also Read: How to Install Jenkins on Ubuntu 24.04 Step-by-Step

Leave a Comment

Your email address will not be published. Required fields are marked *