Step-by-Step Guide to Installing and Configuring Gitea from Binary on Ubuntu 24.04 VPS for Self-Hosting Git Repositories

Introduction

At ByteHosting, we understand the importance of reliable, self-hosted Git management for developers and teams. Gitea is a lightweight, open-source Git service that offers a simple way to host your repositories securely on your own server. In this guide, we will walk you through the step-by-step process of installing Gitea from the official binary on Ubuntu 24.04 VPS. This native installation approach ensures a stable and efficient setup, perfect for those who want full control over their Git environment.

Prerequisites: VPS Setup and Required Packages

Before we begin, ensure you have a fresh Ubuntu 24.04 VPS. Our servers in Frankfurt, Germany, are ideal for hosting such services due to their reliability and high uptime. You should also have root or sudo access to your server.

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

sudo apt update && sudo apt upgrade -y

Install essential packages needed for the installation:

sudo apt install -y git curl sqlite3

If you plan to use a database like MySQL or PostgreSQL instead of SQLite, install the respective packages accordingly. For simplicity, we'll use SQLite in this guide.

Download Gitea Binary from the Official Source

Visit the official Gitea downloads page to find the latest binary release compatible with Linux. As of now, the latest version is 1.20.0, but always check for the newest release.

Use curl or wget to download the binary. For example:

GITEA_VERSION=1.20.0
wget -O gitea https://dl.gitea.io/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64

Make the binary executable and move it to /usr/local/bin for system-wide access:

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

Configure Gitea Service and systemd Unit

To run Gitea as a service, create a dedicated user:

sudo adduser --system --group --disabled-login --gecos "" 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
After=network.target

[Service]
User=gitea
Group=gitea
Type=simple
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=gitea HOME=/home/gitea

[Install]
WantedBy=multi-user.target

Enable and start the Gitea service:

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

Set Up Database and Initial Configuration

Gitea requires an initial configuration file. Create the app.ini file:

sudo nano /etc/gitea/app.ini

Start with a basic configuration, specifying database settings, repository root path, and server URL. For example:

[server]
DOMAIN = your.server.ip.or.domain
HTTP_PORT = 3000
ROOT_URL = http://your.server.ip.or.domain:3000/

[database]
DB_TYPE = sqlite3
PATH = /var/lib/gitea/data/gitea.db

[repository]
ROOT = /var/lib/gitea/repos

Adjust the DOMAIN and ROOT_URL accordingly. Save and exit.

Start Gitea and Access Web Interface

Ensure the service is running:

sudo systemctl restart gitea

Open your browser and navigate to http://your.server.ip.or.domain:3000. You should see the Gitea web setup page. Follow the on-screen instructions to complete the initial setup, creating your admin account and configuring repositories.

Secure Gitea with SSL and Firewall Rules

For production, securing your Gitea instance with SSL is essential. You can use Let's Encrypt for free SSL certificates. Install Certbot:

sudo apt install certbot

Obtain and install the certificate:

sudo certbot certonly --standalone -d your.server.domain

Configure your web server (e.g., Nginx) to proxy requests and enable SSL. Also, ensure your firewall allows traffic on ports 80, 443, and 3000:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 3000/tcp

Verify Installation and Troubleshoot Common Issues

Check the status of the Gitea service:

sudo systemctl status gitea

If you encounter issues, review logs located in /var/lib/gitea/log. Common problems include permission errors, incorrect configuration, or firewall restrictions.

Conclusion

Installing Gitea from the official binary on Ubuntu 24.04 VPS provides a straightforward and reliable way to self-host your Git repositories. By following our step-by-step guide, you can set up a secure, high-performance Git server tailored to your needs. At ByteHosting, we’re committed to providing the infrastructure that powers your development projects—trust us for your hosting needs in Frankfurt and beyond.

Read more