How to Install and Configure Gitea from Binary on Ubuntu 24.04 VPS for Self-Hosting Git Repositories

Introduction

At ByteHosting, we understand the importance of having a reliable, self-hosted Git server for managing your projects securely and efficiently. If you're looking to set up Gitea on an Ubuntu 24.04 VPS, installing it from the binary is a straightforward and lightweight approach. In this guide, we’ll walk you through the process of installing and configuring Gitea from binary on Ubuntu 24.04, ensuring you can host your repositories with minimal fuss and maximum control.

Prerequisites: VPS Setup and Required Packages

Before we begin, ensure your VPS is running Ubuntu 24.04 and that you have root or sudo access. We recommend choosing a reliable VPS plan from ByteHosting, such as our Xeon or Ryzen Virtual Servers, which provide the performance and stability needed for hosting Git repositories.

Next, update your system packages to ensure everything is current:

sudo apt update && sudo apt upgrade -y

Install essential packages needed for Gitea:

sudo apt install -y git sqlite3 wget ca-certificates

While Gitea supports various databases, SQLite is sufficient for small to medium setups and simplifies the installation process.

Download Gitea Binary for Linux from Official Source

Visit the official Gitea downloads page to find the latest binary release. We recommend choosing the latest stable version for security and features.

Download the binary directly to your server:

wget -O /usr/local/bin/gitea https://dl.gitea.io/gitea/latest/gitea--linux-amd64

Replace <version> with the actual version number, for example, 1.20.4. Make the binary executable:

sudo chmod +x /usr/local/bin/gitea

This binary is now ready to run, but we need to set it up as a service for easy management and auto-start on boot.

Configure Gitea as a systemd Service for Auto-Start

Creating a dedicated user for Gitea enhances security:

sudo adduser --system --group --disabled-login --no-create-home gitea

Next, create directories for Gitea data and configuration:

sudo mkdir -p /var/lib/gitea/{custom,data,log} /etc/gitea

Set ownership:

sudo chown -R gitea:gitea /var/lib/gitea /etc/gitea

Create a systemd service file:

sudo nano /etc/systemd/system/gitea.service

Insert the following configuration:

[Unit]
Description=Gitea (Git with a cup of tea)
After=network.target

[Service]
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=/var/lib/gitea

[Install]
WantedBy=multi-user.target

Save and close the file. Reload systemd, enable, and start Gitea:

sudo systemctl daemon-reload
sudo systemctl enable gitea
sudo systemctl start gitea

Check the service status:

sudo systemctl status gitea

If everything is running smoothly, Gitea is now set to start automatically on server boot.

Set Up Reverse Proxy with Nginx for HTTPS Access

For secure access, configure Nginx as a reverse proxy. Install Nginx if you haven't already:

sudo apt install -y nginx

Obtain an SSL certificate, for example, via Let's Encrypt:

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com

Configure Nginx to proxy requests to Gitea:

sudo nano /etc/nginx/sites-available/gitea

Insert the following configuration, replacing yourdomain.com with your actual domain:

server {
    listen 80;
    server_name yourdomain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;

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

Enable the site and restart Nginx:

sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Initial Gitea Setup and Admin Configuration

Access your Gitea instance via

Read more