How to Run Multiple Self-Hosted GitHub Actions Runners on the Same Ubuntu Linux Virtual Machine

Github logo

This guide provides a detailed step-by-step tutorial on how to set up and run several self-hosted GitHub Actions runners on the same Ubuntu Linux Virtual Machine (VM). This setup allows for increased flexibility and customization in your continuous integration and deployment workflows.

Note: Ensure you replace all placeholder text (e.g., projectnamegithubuserYOUR_UNIQUE_CHECKSUMYOUR_PERSONAL_ACCESS_TOKEN) with your specific details.

Prerequisites

Ensure you have an Ubuntu Linux VM set up and have sudo privileges. You also need to install curl and tar if they are not already installed.

Step 1: Set the Working Directory

Start by setting the working directory for your GitHub Actions runner. In this guide, we’ll use /home/$HOME/actions-runner as the working directory. You can create this directory using the mkdir command:

export ACTIONS=/home/$HOME/actions-runner
mkdir $ACTIONS

Step 2: Create and Navigate into the Project Directory

Create a new directory for your project within the working directory and navigate into it. Replace projectname with your specific project’s name.

cd $ACTIONS
mkdir projectname && cd projectname

Step 3: Download the GitHub Actions Runner Package

Download the GitHub Actions runner package for Linux x64 using curl. The URL provided corresponds to a specific version of the runner (v2.304.0 in this case).

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

Step 4: Verify the Checksum of the Downloaded Package

Verify the integrity of the downloaded package by comparing its SHA256 checksum with the known checksum provided by GitHub. Replace YOUR_UNIQUE_CHECKSUM with the actual checksum provided by GitHub.

echo "YOUR_UNIQUE_CHECKSUM  actions-runner-linux-x64-2.304.0.tar.gz" | shasum -a 256 -c

If the output says OK, it means the downloaded package is not corrupted and you can proceed to the next step.

Step 5: Extract the Runner Package

Extract the contents of the runner package using the tar command.

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

Step 6: Configure the GitHub Actions Runner

Now, configure the GitHub Actions runner by running the config.sh script with the appropriate parameters: the name of the runner, the URL of your GitHub repository, and a personal access token. Replace projectnamegithubuser, and YOUR_PERSONAL_ACCESS_TOKEN with your specific details.

./config.sh --name projectname --url https://github.com/githubuser/projectname --token YOUR_PERSONAL_ACCESS_TOKEN

Step 7: Install and Start the GitHub Actions Runner Service

Finally, install and start the runner as a service using the svc.sh script.

sudo ./svc.sh install
sudo ./svc.sh start

And that’s it! You’ve successfully set up a self-hosted GitHub Actions runner on your Ubuntu Linux VM. Repeat the steps from 2 to 7 for each project for which you want to run a separate self-hosted runner.

Remember to regularly update your runners to ensure they have the latest features and security updates.

Leave a Reply

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