Introduction
Setting up a self-hosted runner in GitHub Actions provides you with the flexibility to run workflows on your own hardware. This can be more efficient for specific use cases, like needing specialized software, or controlling the environment for security reasons. This guide will walk you through the steps to configure a self-hosted runner for your GitHub repository.
Prerequisites
Before you begin, make sure you have:
A GitHub repository where you want to add the self-hosted runner.
A machine (physical or virtual) with a supported operating system (e.g., Ubuntu, macOS, Windows).
Administrator access to the machine.
Click on self-hosted runners → New Runner
Click on Linux
Step 2: Choose Your Operating System
- Choose the operating system that matches your machine (e.g., Linux, macOS, or Windows).
- GitHub will display a set of commands that you need to run on your machine to set up the runner.
Step 3: Download and Configure the Runner
On your host machine, open a terminal or command prompt.
Run the commands provided by GitHub to download the runner package. For example, on Linux, you might use:
mkdir actions-runner && cd actions-runner
curl -o actions-runner-linux-x64-2.305.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.305.0/actions-runner-linux-x64-2.305.0.tar.gz
tar xzf ./actions-runner-linux-x64-2.305.0.tar.gz
- Once the download is complete, configure the runner:
./config.sh --url https://github.com/your-username/your-repo --token YOUR_RUNNER_TOKEN
Replace your-username, your-repo, and YOUR_RUNNER_TOKEN with the appropriate values. The token is provided in the GitHub repository settings where you are setting up the runner.
Step 4: Install and Start the Runner
- After configuring, you can start the runner with:
./run.sh
- To install the runner as a service (so it starts automatically on boot), run:
sudo ./svc.sh install
sudo ./svc.sh start
Step 5: Use the Self-Hosted Runner in Your Workflows
- Now that your runner is configured and running, you can specify it in your GitHub Actions workflow. Here’s an example of a workflow file:
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- name: Run a one-line script
run: echo "Hello, world!"
Commit this file to your repository, and the workflow will run on your self-hosted runner.
Step 6: Monitor and Manage the Runner
You can monitor the runner’s status from the Actions tab in your GitHub repository.
To remove the runner, stop it using sudo ./svc.sh stop and then remove it using sudo ./svc.sh uninstall.
Go Through Our YouTube Tutorial
For a comprehensive understanding and to master configuring a self-hosted runner in GitHub Actions, make sure to check out our detailed YouTube tutorials. We cover every key aspect, offer hands-on labs, and share insider tips to help you succeed.
To help you learn how to set up a self-hosted runner in GitHub Actions, our YouTube tutorial is available in English.
Connect with Us!
Stay connected with us for the latest updates, tutorials, and exclusive content:
WhatsApp:-https://www.whatsapp.com/channel/0029VaeX6b73GJOuCyYRik0i
facebook:-https://www.facebook.com/S3CloudHub
youtube:-https://www.youtube.com/@s3cloudhub
Connect with us today and enhance your learning journey!