Self-hosting a Git server on your VPS gives you complete control over your code repositories, no per-user pricing, and unlimited private repos. Whether you choose Gitea (lightweight, Go-based) or GitLab CE (full-featured, Ruby-based), this guide walks through the entire setup process on a Ubuntu 24.04 VPS. Before you start, compare VPS plans on our comparison table to ensure your server has enough resources for your chosen platform.
Prerequisites
- A VPS running Ubuntu 24.04 LTS with at least 1 vCPU and 1 GB RAM (2 GB+ recommended for GitLab).
- Root or sudo access.
- A domain name (or subdomain) pointed to your VPS IP for HTTPS access.
- Ports 22 (SSH), 80 (HTTP), and 443 (HTTPS) open in your firewall.
Option 1: Installing Gitea (Lightweight, < 1 GB RAM)
Gitea is the most resource-efficient self-hosted Git platform. It’s written in Go, uses SQLite by default, and runs comfortably on a 1 GB RAM VPS.
Step 1: Install Dependencies
sudo apt update && sudo apt upgrade -y
sudo apt install -y git curl sqlite3
Step 2: Create a Dedicated User
sudo adduser --system --shell /bin/bash --gecos "Git Version Control" --group --disabled-password --home /home/git git
Step 3: Download and Install Gitea
sudo mkdir -p /var/lib/gitea /etc/gitea /usr/local/bin
sudo chown -R git:git /var/lib/gitea /etc/gitea
sudo wget -O /usr/local/bin/gitea https://dl.gitea.com/gitea/1.22/gitea-1.22-linux-amd64
sudo chmod +x /usr/local/bin/gitea
Step 4: Create systemd Service
sudo tee /etc/systemd/system/gitea.service << EOF
[Unit]
Description=Gitea (Git with a cup of tea)
After=network.target
[Service]
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
WorkingDirectory=/var/lib/gitea
User=git
Group=git
Restart=always
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now gitea
Step 5: Set Up Nginx Reverse Proxy
sudo apt install -y nginx certbot python3-certbot-nginx
sudo tee /etc/nginx/sites-available/gitea << EOF
server {
listen 80;
server_name git.yourdomain.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
}
EOF
sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d git.yourdomain.com
Visit https://git.yourdomain.com to complete the Gitea web installer. Choose SQLite3 as the database, set your admin credentials, and you’re done.
Option 2: Installing GitLab CE (Full-Featured, 2 GB+ RAM)
GitLab Community Edition includes CI/CD pipelines, container registry, issue tracking, and wiki pages. It’s heavier — expect 1.5–2 GB RAM usage at idle — but offers more built-in features.
Step 1: Install Dependencies
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl openssh-server ca-certificates tzdata perl
Step 2: Add GitLab Repository and Install
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo EXTERNAL_URL="https://git.yourdomain.com" apt install -y gitlab-ce
Step 3: Configure Firewall
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
Step 4: Get Initial Root Password
sudo cat /etc/gitlab/initial_root_password
Visit https://git.yourdomain.com and log in with username root and the initial password. GitLab automatically handles SSL via Let’s Encrypt if your domain DNS resolves correctly.
Post-Installation Hardening
- Enable SSH Git access: Add your public key to Gitea/GitLab under User Settings > SSH Keys. Clone repos using [email protected]:username/repo.git.
- Set up automated backups: For Gitea, run gitea dump –file /backups/gitea-$(date +%Y%m%d).zip via cron. For GitLab, use sudo gitlab-backup create.
- Configure email: Set up SMTP in Gitea (app.ini) or GitLab (gitlab.rb) so users receive registration and notification emails.
- Enable two-factor authentication: Enforce 2FA for all users in your Git platform’s admin settings.
- Monitor disk usage: Git repositories grow fast. Set up a cron job to alert you when /var/lib/gitea or /var/opt/gitlab exceeds 80% usage.
Which Should You Choose?
Choose Gitea if: You want a lightweight, fast Git server for a small team (1–10 developers). It runs on a $5–10/month VPS and uses under 200 MB RAM at idle. Setup takes 15 minutes.
Choose GitLab CE if: You need built-in CI/CD runners, container registry, and project management. Budget at least 2 GB RAM and 20 GB storage. Setup takes 30–45 minutes.
Both platforms support standard Git workflows — push, pull, merge requests, branching — and integrate with popular CI/CD tools. Self-hosting eliminates per-user SaaS fees and gives you full data ownership. Check our VPS comparison table to find the right server specs for your self-hosted Git setup.




Leave a Reply
You must be logged in to post a comment.