Install GitHub Actions runner on Ubuntu

To download and install GitHub Actions runner on a Ubuntu machine you will have to run a few commands.

GitHub Actions

GitHub Actions is a platform that simplifies and streamlines the software development process by providing automation and workflows. It empowers developers to automate tasks and processes in their workflow and customize the development process according to their requirements.

With GitHub Actions, developers can create custom workflows for their projects that define the tasks and the order in which they should run. These tasks can include building and testing code, deploying applications, sending notifications, and more. The workflows can be triggered by a variety of events, such as a push or pull requests, comments, or new releases.

Steps to Install GitHub Actions runner on Ubuntu

Create a new folder to hold the runner files using the mkdir command. Navigate to the newly created directory with the cd command. For example:

mkdir actions-runner && cd actions-runner

Download the latest runner package from the Github releases page using the curl command. You can specify the download URL using the -L option to follow redirects. For example:

curl -o actions-runner-linux-x64-2.301.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.301.1/actions-runner-linux-x64-2.301.1.tar.gz

The output of the above command:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  137M  100  137M    0     0  82.3M      0  0:00:01  0:00:01 --:--:-- 98.6M

Replace the URL with the latest release for your platform. You can go to the following section in Github to find the latest URL:

Organization account/Your account >> Settings >> Actions >> Runners

Runners section

Click “Linux”

In the bottom pane, you will see the exact URL to download.

Validate the integrity of the downloaded package by verifying its SHA-256 hash. This is an optional step but can provide an extra level of security. To do this, use the echo command to print the hash and the shasum command to validate it. For example:

echo "3ee9c3b83de642f919912e0594ee2601835518827da785d034c1163f8efdf907  actions-runner-linux-x64-2.301.1.tar.gz" | shasum -a 256 -c

If the validation is successful, you should see the message “actions-runner-linux-x64-2.301.1.tar.gz: OK”. If the validation fails, you should download the package again and retry the validation.

Extract the runner installer from the downloaded package using the tar command. For example:

tar xzf ./actions-runner-linux-x64-2.301.1.tar.gz

This will extract the runner files to the current directory.

Configure and register the runner with Github

Once you have downloaded and extracted the GitHub Actions runner, the next steps involve configuring and registering the runner with Github. From the same page, you will get the config part also which you need to run:

To configure the runner, run the config.sh script, which will guide you through the process of setting up and registering the runner with Github. You will need to provide the URL of your Github repository and the registration token generated when you added the runner to your repository. Once, you run the ./config.sh –url command:

./config.sh --url <YourURL> --token<YourToken>

You will see the output like this:

--------------------------------------------------------------------------------
|        ____ _ _   _   _       _          _        _   _                      |
|       / ___(_) |_| | | |_   _| |__      / \   ___| |_(_) ___  _ __  ___      |
|      | |  _| | __| |_| | | | | '_ \    / _ \ / __| __| |/ _ \| '_ \/ __|     |
|      | |_| | | |_|  _  | |_| | |_) |  / ___ \ (__| |_| | (_) | | | \__ \     |
|       \____|_|\__|_| |_|\__,_|_.__/  /_/   \_\___|\__|_|\___/|_| |_|___/     |
|                                                                              |
|                       Self-hosted runner registration                        |
|                                                                              |
--------------------------------------------------------------------------------

# Authentication


√ Connected to GitHub

# Runner Registration
  • Enter the name of the runner group to add this runner to: [press Enter for Default]: Press enter for this command.
  • Enter the name of runner: [press Enter for ip-…]: <Enter Any Name you want to keep for your runner>
  • This runner will have the following labels: ‘self-hosted’, ‘Linux’, ‘X64’ Enter any additional labels (ex. label-1,label-2): [press Enter to skip]: Enter your own label like staging-server-runner
  • Enter name of work folder: [press Enter for _work]: Press enter key.

Run the service:

Run the following command:

./run.sh

The ./run.sh command is responsible for starting the GitHub Actions runner and establishing a connection with Github. It kicks off the runner service, which then proceeds to execute workflows and jobs for your repository. The run.sh script is situated in the ./actions-runner the directory that was created during the process of extracting the runner files. This command displays real-time log output that can be used to monitor the runner’s activities.

It’s important to note that running this command only starts the runner service in the current terminal session. Hence, the runner service will stop running if you close the terminal or if your server restarts. To ensure the runner service runs continuously, you can install it as a service using the sudo ./svc.sh install command which is explained in the next section.

Output:

√ Connected to GitHub

Current runner version: '2.301.1'
2023-02-15 07:50:44Z: Listening for Jobs

Set up Github Actions runner as a service:

Run the following command:

sudo ./svc.sh install

The output will be like this:

Creating launch runner in /etc/systemd/system/actions.runner.YourRunner.service
Run as user: ubuntu
Run as uid: 1000
gid: 1000
Created symlink /etc/systemd/system/multi-user.target.wants/actions.runner.YourRunner.service → /etc/systemd/system/actions.runner.YourRunner.service.

The command sudo ./svc.sh install installs the GitHub Actions runner as a service on your Ubuntu machine. This installation ensures that the runner starts automatically upon boot, making it a more dependable solution for continuous integration and deployment. Running this command creates a new systemd service unit for the runner and enables it to start automatically upon booting. The runner service runs in the background and can be managed using systemd commands. By setting up the runner as a service, you can be certain that it will always run, even after a system reboot or a user logout.

Your runner has been running now and you can verify the same by going to /settings/actions/runners on Github Site.

Github Actions runner running

The green indicator indicates that the runner is up and running.