L o a d i n g
🚀 How to Set Up a GitLab Runner on Your Server for CI CD Deployment Tutorial

🚀 How to Set Up a GitLab Runner on Your Server for CI CD Deployment

GitLab CI/CD enables seamless automation for building, testing, and deploying your applications. One of the key components to achieve this is GitLab Runner — an agent that runs your pipelines. In this post, you’ll learn how to set up a GitLab Runner on your own server to enable CI/CD for your projects.

✅ Prerequisites

Before we start, make sure you have:

  • A server (Ubuntu, Debian, CentOS, etc.) with sudo/root access.

  • A GitLab account and a project repository.

  • Git installed on the server.

🔧 Step-by-Step Installation

1. Download the GitLab Runner Binary

curl -L https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64 -o /usr/local/bin/gitlab-runner

Then make it executable:

chmod +x /usr/local/bin/gitlab-runner

2. Create a GitLab Runner User

useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

3. Install and Start the Service

gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner gitlab-runner start

4. Register the Runner with Your GitLab Project

Go to GitLab > Your Project > Settings > CI/CD > Runners > Expand, and copy the URL and Registration Token.

Then run:

gitlab-runner register
You will be asked a few prompts:
Prompt Your Answer
Enter the GitLab instance URL e.g. https://gitlab.com or self-hosted
Enter the registration token Paste the token from GitLab
Enter a description e.g. my-runner
Enter tags Optional, e.g. deploy
Executor shell (or docker, etc.)

5. Test Your Runner

Create a .gitlab-ci.yml file in your project root:

stages: - test job_test: stage: test script: - echo "GitLab Runner is working!"

Commit and push it to GitLab. If everything is set up correctly, your job should run automatically.

🔐 Bonus: Allow Deployment via SSH

If you want your runner to deploy to another server (e.g., production), set up SSH keys:

  1. On your server where the runner runs:

     
    ssh-keygen -t rsa -b 4096 -C "gitlab-runner@ci"
  2. Add the public key (~/.ssh/id_rsa.pub) to your target server’s ~/.ssh/authorized_keys.

  3. Add the private key to GitLab CI/CD Variables as SSH_PRIVATE_KEY.

  4. Update .gitlab-ci.yml to use it during deploy.

🧠 Conclusion

Setting up GitLab Runner on your own server gives you full control over your CI/CD process. It's cost-effective, customizable, and powerful for automating testing, building, and deploying software.

If you need help setting up advanced runners (like with Docker-in-Docker, deployment to Kubernetes, or custom runners per branch), feel free to reach out!

1 Comments

  • Djustin
    Djustin
    d******om 20:18 WIB Wed, June 4 2025

    nice blog👍

Leave a Reply