# How to use Amazon EC2 as GitHub self-hosted runner

Setting up a GitHub self-hosted runner on AWS EC2 involves several steps, from creating an EC2 instance to configuring it as a GitHub Actions runner.

First, we need to create Amazon EC2 instance.

Here is a sample instance. You can configure it depending on your needs.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479204827/d82e53a4-72e3-43e1-a750-46bd6ec244d8.png)

After creating instance, connect to the instance.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479206921/e8d9197e-bfe2-4aef-8868-edf480166660.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479208939/bd5e0d2c-caec-48ce-9072-f2786a8b7155.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479211332/938449f7-b115-41fb-8795-7ab6c4300144.png)

Now, enter these commands

*   sudo apt update -y
*   sudo apt install git -y

After installing git, go to the GitHub runners and click “New self-hosted runner”

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479212866/edaa99f2-8862-4ef9-b464-d50c205db51d.png)

Choose Linux x64, this can be different upon your instance OS and architecture.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479214681/a313e52a-f77f-4363-99fd-3e8244810b4d.png)

You’ll see command lines to download and configure the runner in instance.

You just need to copy and run the command lines in the instance.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479216398/1be7258e-084a-4568-a338-3524f0ad6b3f.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479218362/54bc1b07-f90d-408a-9ebc-381bb1479187.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479220114/82a0175b-2b21-4151-bb87-91202cf4e41d.png)

Now, let’s check the GitHub runner. We got the runner but its status is offline.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479221647/d28d0360-1e36-4c22-8e9a-b744ed6be2d4.png)

Go to the instance and run these commands

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479223626/5f17b2fd-dec1-44a4-a790-773ac1b64fd4.png)

Check again the runner.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479225418/cea3a1ed-d23e-423d-8078-e36ddca41b8c.png)

We got our self-hosted runner.

Now, I’ll continue to show how to use that runner in the GitHub Actions yml. It’s just that you need to type the runner labels in runs-on to use the self-hosted runner. Here is an example

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479227009/48064e2d-e9df-472e-936a-dc7c8f4a0540.png)

Now, I’ll continue to show how to remove the runner.

Before we remove the runner, we need to stop and uninstall the runner service in the instance.

Run these commands

*   sudo ./svc.sh stop
*   sudo ./svc.sh uninstall

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479228694/40abff3c-32cc-4403-9ae7-e244f8e305ec.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479230526/c6cba552-a4a5-462f-8f74-5c550645f779.png)

Now, go to the GitHub runner option and click “remove runner”

You just need to copy and run the remove command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479232348/f072b1ea-97bf-4da9-a6e6-febd6782c8fa.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479233724/60bfa85d-f0c8-4e58-bd54-4c8680d74a4e.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479235748/636b6138-8e09-44af-827b-58a1be496268.png)

Check in the GitHub runner. It’ll be gone.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1745479237757/7d793856-d63b-4dc3-b0bc-214449917cec.png)

This guideline will create a self-hosted GitHub Actions runner on an AWS EC2 instance, allowing you to run CI/CD jobs directly on your own infrastructure. I hope you enjoy!
