Set Up Gitea Git Server on VPS
Gitea is a lightweight self-hosted Git service written in Go that uses only ~100MB of RAM but includes a complete feature set: repository browser, pull requests, issue tracker, CI/CD (Gitea Actions), and webhooks. It's ideal for teams that need a code repository on their own server without relying on GitHub.
Install Gitea
# Create a user for Gitea
sudo adduser --system --group --shell /bin/bash --home /home/gitea gitea
# Download Gitea binary (check latest version at gitea.io/releases)
sudo wget -O /usr/local/bin/gitea \
https://dl.gitea.com/gitea/1.22.0/gitea-1.22.0-linux-amd64
sudo chmod +x /usr/local/bin/gitea
# Create directories
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R gitea:gitea /var/lib/gitea
sudo mkdir /etc/gitea
sudo chown root:gitea /etc/gitea
sudo chmod 770 /etc/gitea
Set Up systemd Service
sudo nano /etc/systemd/system/gitea.service
[Unit]
Description=Gitea
After=syslog.target
After=network.target
After=mysql.service
[Service]
Type=simple
User=gitea
Group=gitea
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=gitea HOME=/home/gitea GITEA_WORK_DIR=/var/lib/gitea
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now gitea
Configure via Web Installer
Open your browser to http://YOUR_VPS_IP:3000 and fill in the configuration:
- Database: SQLite3 (simple, small) or MySQL/PostgreSQL (for production)
- Site URL:
https://git.yourdomain.com - Admin Username/Password
Set Up Nginx Reverse Proxy + SSL
sudo nano /etc/nginx/sites-available/gitea
server {
listen 80;
server_name git.yourdomain.com;
return 301 https://$host$request_uri;
}
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;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 100M; # For pushing large repositories
}
}
sudo certbot --nginx -d git.yourdomain.com
sudo a2ensite gitea
sudo systemctl reload nginx
SSH_PORT = 2222 Users will then clone with git clone ssh://[email protected]:2222/user/repo.git
Verify Gitea is Working Correctly
# Check service status
systemctl status gitea
# View logs
journalctl -u gitea -n 50
# Check if port 3000 is running
ss -tlnp | grep 3000
# Test git clone
git clone https://git.yourdomain.com/admin/test-repo.git
gitea dump -c /etc/gitea/app.ini This creates a zip file containing the database, repositories, and configuration all in one archive.
Common Issues & Troubleshooting
Cannot Access Port 3000 After Installation
Your firewall may be blocking port 3000, or Gitea may only be binding to localhost:
# Open port temporarily for setup
sudo ufw allow 3000/tcp
# After setup is complete, close port 3000 and use Nginx proxy instead
sudo ufw delete allow 3000/tcp
Git Push Fails — "repository does not exist"
Check that the remote URL is correct and the user has push permissions:
# Check remote URL
git remote -v
# Set URL again if incorrect
git remote set-url origin https://git.yourdomain.com/username/repo.git
Web Page Loads Very Slowly on First Load
The Gitea binary may be swapped out of RAM. Consider increasing memory or expanding swap space:
# Check if Gitea is swapped out of RAM
sudo cat /proc/$(pgrep gitea)/status | grep VmSwap
# Increase RAM or expand swap
# See VPS swap memory article for details
Webhooks Not Triggering on Push
By default, Gitea blocks webhooks to localhost for security reasons. You need to enable it in the config:
sudo nano /etc/gitea/app.ini
[webhook]
ALLOWED_HOST_LIST = external, loopback, private # Enable loopback for local webhooks
Frequently Asked Questions
How are Gitea and GitLab different? Which should I use?
GitLab has more features (built-in CI/CD, container registry, security scanning) but requires 4GB+ RAM. Gitea is much lighter (~100–200MB RAM) and better for small VPS or teams that don't need the full GitLab ecosystem. If you only need Git hosting + pull requests + basic CI, Gitea is the better choice.
Does Gitea Support GitHub Actions?
Gitea includes Gitea Actions, which is compatible with GitHub Actions syntax. Most workflows written for GitHub Actions will run on Gitea with few or no changes. You do need to install a separate act runner.
How Can I Migrate a Repository from GitHub to Gitea?
You can do this through the UI: Explore → + → Migrate External Git → select GitHub → enter your token and repo URL. Gitea will clone all commits, branches, issues, pull requests, and labels for you.