In an era where code privacy and control are increasingly important, hosting your own Git server offers compelling advantages over relying solely on third-party platforms. Whether you’re managing proprietary code, want unlimited private repositories, or simply prefer self-hosting, Gitea provides an excellent lightweight alternative to GitHub and GitLab.

This comprehensive guide will walk you through setting up Gitea on a RamNode VPS, creating your own private Git hosting solution that you fully control.

Why Choose Gitea?

Gitea is a community-managed fork of Gogs, designed to be lightweight, fast, and easy to deploy. Unlike heavier alternatives like GitLab, Gitea runs efficiently on modest hardware while still providing essential features like pull requests, issue tracking, and organization management.

Key advantages of Gitea:

  • Minimal resource requirements (runs well on 1GB RAM)
  • Fast and responsive web interface
  • Git repository hosting with web-based management
  • Issue tracking and pull request workflows
  • User and organization management
  • Webhook support for CI/CD integration
  • Active development and community support

Why RamNode for Hosting?

RamNode offers reliable VPS hosting with excellent performance-to-price ratios, making it ideal for self-hosted applications like Gitea. Our SSD-based VPS instances provide the fast disk I/O that Git operations benefit from, while our competitive pricing makes it cost-effective for personal or small team use.

Prerequisites

Before starting, ensure you have:

  • A RamNode VPS (minimum 1GB RAM, 20GB storage recommended)
  • SSH access to your server
  • A domain name (optional but recommended)
  • Basic familiarity with Linux command line

Initial Server Setup

First, connect to your RamNode VPS via SSH and update the system:

# Connect to your VPS
ssh root@your-server-ip

# Update system packages
apt update && apt upgrade -y

# Install essential packages
apt install -y curl wget git unzip

Create a dedicated user for Gitea (running as root is not recommended):

# Create gitea user
adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git

# Create necessary directories
mkdir -p /var/lib/gitea/{custom,data,log}
chown -R git:git /var/lib/gitea/
chmod -R 750 /var/lib/gitea/
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 770 /etc/gitea

Install and Configure Database

While Gitea can use SQLite for small installations, PostgreSQL or MySQL provide better performance for production use. We’ll use PostgreSQL:

# Install PostgreSQL
apt install -y postgresql postgresql-contrib

# Switch to postgres user and create database
sudo -u postgres psql

# In PostgreSQL prompt:
CREATE USER gitea WITH PASSWORD 'your_secure_password_here';
CREATE DATABASE giteadb WITH OWNER gitea TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
\q

Download and Install Gitea

Download the latest Gitea binary:

# Check latest version at https://github.com/go-gitea/gitea/releases
GITEA_VERSION="1.21.3"  # Replace with current version

# Download Gitea binary
wget -O /tmp/gitea https://dl.gitea.io/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64

# Move to system location and set permissions
mv /tmp/gitea /usr/local/bin/gitea
chmod +x /usr/local/bin/gitea

# Verify installation
/usr/local/bin/gitea --version

Create Systemd Service

Create a systemd service file to manage Gitea:

cat > /etc/systemd/system/gitea.service << EOF
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
After=postgresql.service

[Service]
RestartSec=2s
Type=notify
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
EOF

Enable and start the service:

systemctl daemon-reload
systemctl enable gitea
systemctl start gitea
systemctl status gitea

Configure Reverse Proxy with Nginx

Install and configure Nginx as a reverse proxy:

# Install Nginx
apt install -y nginx

# Create Nginx configuration
cat > /etc/nginx/sites-available/gitea << EOF
server {
    listen 80;
    server_name your-domain.com;  # Replace with your domain

    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;
    }
}
EOF

# Enable the site
ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default

# Test and reload Nginx
nginx -t
systemctl restart nginx

SSL Certificate with Let’s Encrypt

Secure your Gitea installation with a free SSL certificate:

# Install Certbot
apt install -y certbot python3-certbot-nginx

# Obtain SSL certificate
certbot --nginx -d your-domain.com

# Verify auto-renewal
certbot renew --dry-run

Complete Gitea Setup

Navigate to your domain in a web browser to complete the Gitea setup:

  1. Database Settings:
    • Database Type: PostgreSQL
    • Host: 127.0.0.1:5432
    • Username: gitea
    • Password: (the password you set earlier)
    • Database Name: giteadb
  2. General Settings:
    • Site Title: Your choice
    • Repository Root Path: /home/git/gitea-repositories
    • Git LFS Root Path: /var/lib/gitea/data/lfs
    • Run As Username: git
  3. Administrator Account:
    • Create your admin user account
  4. Optional Settings:
    • Configure email settings for notifications
    • Set up additional security options

Post-Installation Security

After setup, secure the configuration file:

chmod 750 /etc/gitea
chmod 640 /etc/gitea/app.ini

Configure firewall rules:

# Install UFW if not present
apt install -y ufw

# Allow SSH, HTTP, and HTTPS
ufw allow ssh
ufw allow http
ufw allow https

# Enable firewall
ufw --force enable

Configure Backups

Set up automated backups to protect your repositories:

# Create backup script
cat > /home/git/backup-gitea.sh << 'EOF'
#!/bin/bash
BACKUP_DIR="/home/git/backups"
DATE=$(date +%Y%m%d_%H%M%S)

# Create backup directory
mkdir -p $BACKUP_DIR

# Stop Gitea service
systemctl stop gitea

# Backup database
sudo -u postgres pg_dump giteadb > $BACKUP_DIR/gitea_db_$DATE.sql

# Backup Gitea data
tar -czf $BACKUP_DIR/gitea_data_$DATE.tar.gz /var/lib/gitea/ /etc/gitea/

# Start Gitea service
systemctl start gitea

# Keep only last 7 days of backups
find $BACKUP_DIR -name "gitea_*" -mtime +7 -delete

echo "Backup completed: $DATE"
EOF

# Make executable
chmod +x /home/git/backup-gitea.sh

# Add to crontab for daily backups at 2 AM
(crontab -u git -l 2>/dev/null; echo "0 2 * * * /home/git/backup-gitea.sh") | crontab -u git -

Performance Optimization

For better performance, especially with larger repositories:

# Edit Gitea configuration
nano /etc/gitea/app.ini

# Add or modify these sections:
[server]
DISABLE_SSH = false
SSH_DOMAIN = your-domain.com
SSH_PORT = 22

[database]
MAX_IDLE_CONNS = 30
MAX_OPEN_CONNS = 300

[indexer]
ISSUE_INDEXER_TYPE = bleve
REPO_INDEXER_ENABLED = true

[cache]
ENABLED = true
ADAPTER = memory
INTERVAL = 60

Restart Gitea after configuration changes:

systemctl restart gitea

Using Your Git Server

Once setup is complete, you can:

  1. Create repositories through the web interface
  2. Clone repositories using standard Git commands:
    git clone https://your-domain.com/username/repository.git
    
  3. Push existing repositories to your server:
    git remote add origin https://your-domain.com/username/repository.gitgit push -u origin main
    

Maintenance and Updates

Keep your Gitea installation updated:

# Check current version
/usr/local/bin/gitea --version

# Download new version (replace with latest)
wget -O /tmp/gitea https://dl.gitea.io/gitea/NEW_VERSION/gitea-NEW_VERSION-linux-amd64

# Stop service, backup, and update
systemctl stop gitea
cp /usr/local/bin/gitea /usr/local/bin/gitea.backup
mv /tmp/gitea /usr/local/bin/gitea
chmod +x /usr/local/bin/gitea
systemctl start gitea

Troubleshooting Common Issues

Service won’t start:

  • Check logs: journalctl -u gitea
  • Verify permissions on directories
  • Ensure database is running

Can’t access web interface:

  • Check if Gitea is running: systemctl status gitea
  • Verify Nginx configuration: nginx -t
  • Check firewall settings

Git operations are slow:

  • Monitor server resources: htop
  • Consider upgrading VPS if consistently high usage
  • Check database performance

Conclusion

Running your own Git server with Gitea on a RamNode VPS provides complete control over your code repositories while maintaining the collaborative features you need. With proper setup and maintenance, this solution offers excellent performance and reliability for personal projects or small teams.

The combination of Gitea’s lightweight design and RamNode’s reliable infrastructure creates a cost-effective alternative to hosted Git services, with the added benefits of privacy, customization, and unlimited repositories.

Remember to monitor your server regularly, keep backups current, and stay updated with Gitea releases to ensure optimal performance and security.