How to Install Gitea on Ubuntu 24.04 VPS for Self-Hosted Git Hosting

Introduction

At ByteHosting, we understand the importance of having a reliable, self-hosted Git solution for your development projects. If you're looking to set up your own Git server, Gitea is an excellent choice—lightweight, easy to install, and feature-rich. In this step-by-step guide, we’ll show you how to install Gitea on Ubuntu 24.04 VPS, optimized for performance and security. Whether you're a beginner or an experienced user, our instructions will help you deploy Gitea smoothly on your fresh Ubuntu VPS.

Prerequisites: Setting up Your Ubuntu 24.04 VPS

Before we begin, ensure you have a clean Ubuntu 24.04 VPS. At ByteHosting, we offer cost-effective VPS plans in Frankfurt, Germany, with instant deployment and reliable uptime. You’ll need root or sudo access to your server to install Gitea and its dependencies.

If you haven't already, connect to your server via SSH:

ssh username@your_server_ip

Installing Gitea Dependencies and Prerequisites

Gitea requires a few essential packages and a database backend. We recommend using MariaDB for simplicity and performance. First, update your package list:

sudo apt update && sudo apt upgrade -y

Next, install the necessary dependencies:

sudo apt install -y git mariadb-server mariadb-client libmariadb3

Secure your MariaDB installation:

sudo mysql_secure_installation

Follow the prompts to set a root password and secure your database. Then, create a dedicated database and user for Gitea:

sudo mysql -u root -p
MariaDB [(none)]> CREATE DATABASE gitea CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
MariaDB [(none)]> CREATE USER 'giteauser'@'localhost' IDENTIFIED BY 'your_secure_password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON gitea.* TO 'giteauser'@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Downloading and Installing Gitea

Now, let's download the latest Gitea binary. Visit the official Gitea downloads page to find the latest version. For simplicity, we'll use the command line to download it directly:

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

Replace <version> with the latest version number, e.g., 1.20.4. Alternatively, you can check the latest version on their site and update the URL accordingly.

Make the binary executable:

chmod +x gitea

Move it to /usr/local/bin for system-wide access:

sudo mv gitea /usr/local/bin/

Configuring Gitea for First Use

Next, create a dedicated user for Gitea to run under:

sudo adduser --system --group --disabled-password --shell /bin/bash gitea

Set up directories for Gitea:

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

Create a systemd service file to manage Gitea:

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

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

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

Accessing and Configuring Gitea

Open your browser and navigate to http://your_server_ip:3000. You should see the Gitea setup page. Follow the on-screen instructions to complete the initial configuration:

  • Set your database type to MySQL / MariaDB
  • Enter the database details you created earlier
  • Configure your administrator account
  • Adjust server settings as needed

Once completed, you’ll have a fully functional self-hosted Git server. You can now create repositories, manage users, and integrate with your development workflow.

Testing Your Gitea Installation

Test your setup by creating a new repository through the web interface. Clone it locally to verify everything works:

git clone http://your_server_ip:3000/your_username/your_repo.git

If you can push and pull without issues, your Gitea installation is successful.

Troubleshooting Common Issues

  • Gitea not starting: Check the service status with sudo systemctl status gitea. Review logs in /var/log/gitea.
  • Database connection errors: Verify your app.ini configuration and database credentials.
  • Firewall issues: Ensure port 3000 is open in your server’s firewall settings.

Conclusion

Deploying Gitea on your Ubuntu 24.04 VPS is straightforward with the right steps. At ByteHosting, we provide reliable VPS hosting in Frankfurt that’s perfect for hosting your own Git server. With Gitea, you gain a lightweight, secure, and customizable platform for managing your code repositories. Follow our guide, and you'll have your self-hosted Git environment up and running in no time!

Read more