Self-hosting GitLab in your homelab allows you to manage code repositories, CI/CD pipelines, and collaborative development projects in a secure, private environment. This guide walks you through installing and configuring GitLab on your homelab server.
What You’ll Need A server or virtual machine with at least: 4 GB RAM and 2 CPUs (recommended for smaller deployments). 20 GB of storage (more for large repositories or CI/CD). A Linux-based OS (Ubuntu 20.04 or newer is recommended). A static IP or domain name (for remote access). Step 1: Update and Prepare Your Server Log into your server: ssh user@<server_ip> Update the system packages: sudo apt update && sudo apt upgrade -y Install dependencies: sudo apt install -y curl openssh-server ca-certificates Step 2: Install GitLab Add the GitLab repository: curl -s [https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh](https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh) | sudo bash Install GitLab:
Replace <your-domain> with your server’s domain or IP: sudo EXTERNAL_URL="http://<your-domain>" apt install -y gitlab-ee Run the GitLab reconfiguration script: sudo gitlab-ctl reconfigure Step 3: Access the GitLab Web Interface Open your web browser and go to http://<your-domain>. Set a password for the default root user on the first login. Log in using the root username and your new password. Step 4: Configure GitLab Set up email notifications: Edit the /etc/gitlab/gitlab.rb file and configure SMTP settings. Reconfigure GitLab: sudo gitlab-ctl reconfigure Create a new project: Navigate to the Projects tab in the web interface. Click New Project and follow the wizard to create your repository. Step 5: Connect to Your Repository Clone the repository to your local machine: git clone http://<your-domain>/<namespace>/<repository>.git Push your code to the repository: cd <repository> git add . git commit -m "Initial commit" git push origin main Step 6: Enable SSL (Optional) Install Certbot for Let’s Encrypt: sudo apt install -y certbot Generate an SSL certificate: sudo certbot certonly --standalone -d <your-domain> Update GitLab configuration:
Edit /etc/gitlab/gitlab.rb: external_url "https://<your-domain>" nginx['ssl_certificate'] = "/etc/letsencrypt/live/<your-domain>/fullchain.pem" nginx['ssl_certificate_key'] = "/etc/letsencrypt/live/<your-domain>/privkey.pem" Reconfigure GitLab: sudo gitlab-ctl reconfigure Step 7: Configure CI/CD Pipelines (Optional) Add a .gitlab-ci.yml file to your repository root: yaml
stages:
- build
build-job:
stage: build
script:
- echo "Hello, World!" Commit and push the file: git add .gitlab-ci.yml
git commit -m "Add CI/CD pipeline"
git push origin main 2. Check the CI/CD > Pipelines section in the GitLab web interface to monitor the job.: FAQs Q: Is GitLab free to use?
A: Yes, GitLab offers a free tier with all essential features for self-hosting. Paid tiers include advanced features like enhanced security and analytics.
...