How to Host Your Own GitLab Runner on a VPS for Private CI
Shared runners work until they do not. A queue builds up at the wrong hour, a job needs a tool that is not installed, or a build touches files you would rather keep off shared infrastructure. When you host GitLab Runner on a VPS, the machine that runs your pipeline belongs to you, so you control the software, the cache, and who can use it. This guide covers the full setup on Ubuntu 24.04: install, register, pick an executor, and write a pipeline.
A runner is not GitLab itself. GitLab hosts your repositories and schedules jobs, while the runner is a small agent that picks up those jobs and runs them on your server. You can use GitLab.com for hosting and still run your own runner, which is the setup this guide covers. If you want the Git hosting itself on your own server too, you can run a private Git server with Gitea as a separate project.
What You Need Before You Start
You need a VPS with at least 2 GB of RAM and 20 GB of free disk, running Ubuntu 22.04 or 24.04. A 1 GB server can run a shell runner for small jobs, but Docker builds will push it into swap. You also need a GitLab account, a project you can change, and SSH access as a user with sudo. Check the official GitLab Runner documentation for the current supported distributions before you start.
Decide what your jobs need first. A static site build needs Node.js or Hugo, a Docker image build needs Docker on the host, and a deploy job needs SSH keys or API credentials on the runner. That list decides which executor to pick.
Install GitLab Runner on Your VPS
Install from the official GitLab package repository, not from a distribution package that may lag behind:
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
sudo apt-get install gitlab-runner
Check that the service is running:
sudo gitlab-runner status
sudo gitlab-runner verify
The install creates a gitlab-runner system user and a service that starts at boot. The runner does not run jobs until you register it, which tells GitLab this machine is available to take work from a specific project or group.
Register the Runner with GitLab
Create the runner in GitLab first. In your project, open Settings, then CI/CD, then Runners, and select New project runner. GitLab shows a registration token for that runner, which you will paste into the register command on your VPS. Group runners work the same way, from the group settings, and can serve every project in the group.
Run the registration on your VPS. This example registers a Docker executor with a tag, so only jobs that ask for that tag will run here:
sudo gitlab-runner register
--url https://gitlab.com
--token YOUR_REGISTRATION_TOKEN
--executor docker
--docker-image alpine:latest
--description "vps-docker-runner"
--tag-list "docker,linux"
--run-untagged="false"
--locked="false"
Replace the token with the one GitLab showed you, and replace the URL with your self-hosted GitLab address if you run your own instance. The register command writes the result to /etc/gitlab-runner/config.toml, the file you edit later to change concurrency or add another runner. After registration, refresh the Runners page in GitLab. Your new runner should appear as online. If it shows offline, check the log with sudo journalctl -u gitlab-runner -n 50.
Host GitLab Runner on a VPS: Pick Shell or Docker Executor
The executor decides how each job runs. The shell executor runs commands directly on the host, in the gitlab-runner user account. The GitLab Runner Docker executor starts a fresh container for each job from the image named in the pipeline, then removes it when the job ends. The right choice depends on whether your jobs need isolation or direct access to the host.
| Executor | How jobs run | Best for | Watch out for |
|---|---|---|---|
| Shell | Commands run directly on the VPS | Deploys and simple builds | Jobs share the host |
| Docker | Each job runs in a fresh container | Clean, repeatable builds | Needs Docker installed |
Pick the shell executor when your main job is deployment: the runner already has the SSH keys, the deploy scripts, and the tools it needs. Pick Docker when different projects need different runtimes, or when you want each job to start from a clean image instead of whatever the last job left behind. If you go the Docker route, install Docker and Docker Compose on Ubuntu 24.04 first. You can also register two runners on the same VPS, one shell and one Docker, and give each its own tags.
Write Your First .gitlab-ci.yml
The pipeline lives in a .gitlab-ci.yml file at the root of your repository. GitLab reads it on every push and sends each job to a runner that matches its tags. This example has three stages, runs on the Docker runner, and uses a cache so dependency installs do not start from zero on every run:
stages:
- build
- test
- deploy
build-job:
stage: build
tags:
- docker
image: node:22
script:
- npm ci
- npm run build
cache:
key: npm-$CI_COMMIT_REF_SLUG
paths:
- node_modules/
test-job:
stage: test
tags:
- docker
image: node:22
script:
- npm test
deploy-job:
stage: deploy
tags:
- docker
image: alpine:latest
script:
- echo "Deploy step goes here"
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
Tags are the link between the pipeline and the runner. A job with tags: [docker] only runs on a runner that has the docker tag. A runner registered with --run-untagged="false" ignores jobs with no tags, which keeps stray jobs from landing on your private runner by accident. The rules block limits the deploy job to the default branch, so a push to a feature branch builds and tests but never deploys.
Commit the file and push, then watch the first run on the CI/CD Pipelines page. If a job stays pending, the tags do not match any online runner, or the runner is paused. If a job fails with a missing command, the image named in the job does not contain that tool, so use a different image or add an install step.
Lock It Down: Tags, Protected Runners, and the Firewall
A private runner is still a machine that runs code from your repositories, so treat it like a server. Mark the runner as protected in GitLab if it holds deploy credentials, and only protected branches can then use it. That setting stops a job on an unreviewed branch from reaching production secrets. Keep the runner locked to its project or group, and use tags to split runners by purpose: one tag for builds, another for deploys.
Close the ports you do not need. The runner only makes outbound connections to GitLab, so it needs no inbound port open for CI itself. Only SSH should accept inbound traffic. If you have not set up a firewall yet, set up UFW on Ubuntu Server 24.04 and allow only SSH. Store deploy keys and tokens in GitLab CI/CD variables, marked as masked and protected where the option exists, instead of writing them into the pipeline file or the runner config. Rotate them when someone leaves the project.
Keep the Runner Healthy
Open /etc/gitlab-runner/config.toml and check the concurrent setting at the top of the file. It sets how many jobs the runner takes at once. Start with 1 on a 2 GB VPS and raise it only after you have watched memory use during a real build. A second job that starts while the first is still compiling will slow both of them and can push the server into swap.
Disk fills up quietly on a runner host. Docker images, build caches, and old job directories grow between runs, and a full disk fails builds in confusing ways. Check disk use weekly, prune unused Docker images with docker system prune, and clear the runner cache directory when builds start failing for no clear reason. A systemd timer instead of cron works well for a weekly cleanup job, since you get logging and a clear record of each run.
Update the runner with the rest of the system: sudo apt-get update && sudo apt-get install gitlab-runner pulls the latest version from the repository you added at install time. Check the release notes first when you jump several versions, because executor behaviour and config options change between releases. After an update, run sudo gitlab-runner verify and trigger a test pipeline to confirm jobs still pick up. If the runner stops picking up jobs, look at the service log first, then the Runners page in GitLab, which shows whether GitLab sees the runner as online.
Your own runner gives you private CI with full control over the build environment. Start with one runner, one tagged pipeline, and a protected deploy job, then add a second runner or raise concurrency only when a real queue tells you the first runner is the bottleneck.