Install Gitea Private Git Server on VPS
Gitea is a lightweight, self-hosted Git service similar to GitHub but installed on your own VPS. It supports repositories, issue tracking, pull requests, webhooks, and organization management. Written in Go, Gitea uses minimal RAM — a 1GB VPS can comfortably run Gitea with hundreds of repositories.
Install Gitea Using Binary Directly
# Create user for Gitea
sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git
# Create directories
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R git:git /var/lib/gitea/
sudo chmod -R 750 /var/lib/gitea/
sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea
# Download Gitea binary (check latest version at gitea.io)
wget -O /tmp/gitea https://dl.gitea.com/gitea/1.21.11/gitea-1.21.11-linux-amd64
sudo chmod +x /tmp/gitea
sudo mv /tmp/gitea /usr/local/bin/gitea
Create systemd Service
sudo nano /etc/systemd/system/gitea.service
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target network.target mysql.service
[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now gitea
Configure Nginx Reverse Proxy + TLS
sudo nano /etc/nginx/sites-available/gitea
server {
listen 443 ssl;
server_name git.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/git.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/git.yourdomain.com/privkey.pem;
client_max_body_size 512M;
location / {
proxy_pass http://127.0.0.1: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;
}
}
server {
listen 80;
server_name git.yourdomain.com;
return 301 https://$host$request_uri;
}
sudo certbot --nginx -d git.yourdomain.com
sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
Initial Setup via Web
Open your browser to https://git.yourdomain.com. The installation page will appear. Configure the following:
- Database: SQLite3 (sufficient for personal use) or MySQL/PostgreSQL
- Site URL:
https://git.yourdomain.com - SSH Server Port: 22 (must be open in firewall)
- Create first admin account
# After setup is complete, lock the config to prevent web editing
sudo chmod 750 /etc/gitea
sudo chmod 640 /etc/gitea/app.ini
Verify Gitea is Working Correctly
# Check service status
sudo systemctl status gitea
# Check port 3000 is open
sudo ss -tulnp | grep 3000
# View logs
sudo journalctl -u gitea -n 50
# Test cloning via HTTPS
git clone https://git.yourdomain.com/youruser/yourrepo.git
/-/admin where you can view system info, user statistics, and run maintenance tasks such as Git GC and resync repository hooks.
Common Issues & Troubleshooting
Error: "repository not found" after clone
Check directory permissions for Gitea data:
sudo chown -R git:git /var/lib/gitea/
ls -la /var/lib/gitea/data/
sudo systemctl restart gitea
SSH push fails with Permission denied
You must add SSH keys to your Gitea account and authorized_keys:
# Check authorized_keys
cat /home/git/.ssh/authorized_keys
# Should contain gitea-internal command for each key
# If SSH keys in Gitea are not synced, resync them
sudo -u git gitea admin regenerate keys -c /etc/gitea/app.ini
Gitea is very slow with large repositories
Run Git GC to optimize the repository:
sudo -u git gitea admin git repositories gc -c /etc/gitea/app.ini
# Or run gc for a specific repo
cd /var/lib/gitea/data/repositories/user/repo.git
git gc --aggressive
Webhooks not working (ERR_CONNECTION_REFUSED)
Gitea blocks localhost webhooks by default. Configure in app.ini:
sudo nano /etc/gitea/app.ini
[webhook]
ALLOWED_HOST_LIST = external,loopback
sudo systemctl restart gitea
Frequently Asked Questions
How does Gitea differ from GitLab CE?
Gitea uses much less RAM (approximately 100-200MB compared to 2-4GB for GitLab). Gitea is ideal for small VPS instances and small teams. GitLab CE has a more powerful built-in CI/CD system and more comprehensive features for enterprise environments.
How do I backup Gitea?
Use Gitea's built-in dump command, which backs up all repositories, database, configuration, and attachments into a single zip file:
sudo -u git gitea dump -c /etc/gitea/app.ini -w /tmp
Can I migrate a repository from GitHub to Gitea?
Yes. Go to Explore > Migrate Repository, select GitHub as the source platform, enter your token and repository URL. Gitea will clone all code, issues, labels, milestones, and wiki for you.