How to Install and Configure Gitea as a Systemd Service on Ubuntu 24.04 Without Docker

Introduction

At ByteHosting, we understand the importance of having a reliable, self-hosted Git solution for your development projects. Gitea is a lightweight, open-source Git service that is perfect for small teams or individual developers. In this guide, we will show you how to install Gitea as a systemd service on Ubuntu 24.04 without using Docker, providing a native, efficient setup that leverages Ubuntu's system management capabilities.

Prerequisites: Ubuntu 24.04 VPS setup and user permissions

Before we begin, ensure you have a fresh Ubuntu 24.04 VPS from ByteHosting. We recommend using one of our cost-effective KVM VPS plans, such as the Xeon 4GB or Ryzen Virtual Servers, depending on your needs. You should also have root or sudo privileges to install packages and configure services.

Installing Dependencies: Git, SQLite, and Necessary Packages

Gitea requires some essential dependencies. First, update your package list:

sudo apt update

Then, install Git, SQLite, and other required packages:

sudo apt install -y git sqlite3 libsqlite3-dev ca-certificates

These packages are necessary for Gitea to operate smoothly and securely.

Downloading Gitea Binary and Setting Up Directories

Next, download the latest Gitea binary from the official GitHub repository. Visit Gitea releases to find the latest version. For example, to download version 1.20.0:

wget -O gitea https://github.com/go-gitea/gitea/releases/download/v1.20.0/gitea-1.20.0-linux-amd64

Make the binary executable:

chmod +x gitea

Move it to a directory in your PATH, such as /usr/local/bin:

sudo mv gitea /usr/local/bin/

Now, create directories for Gitea data and configuration:

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

Set appropriate ownership:

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

Creating a systemd Service File for Gitea

To run Gitea as a service, create a systemd unit file:

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

Insert the following configuration:

[Unit]
Description=Gitea (Git Service)
After=network.target

[Service]
User=git
Group=git
WorkingDirectory=/var/lib/gitea
ExecStart=/usr/local/bin/gitea web -p 3000
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

[Install]
WantedBy=multi-user.target

Save and close the file.

Starting and Enabling Gitea Service

Reload systemd to recognize the new service:

sudo systemctl daemon-reload

Start Gitea:

sudo systemctl start gitea

Enable it to start on boot:

sudo systemctl enable gitea

Check the service status:

sudo systemctl status gitea

Accessing Gitea Web Interface and Initial Configuration

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, including database setup, admin user creation, and repository settings.

Troubleshooting Common Issues

Permissions Problems

If Gitea fails to start or cannot write to directories, verify that the git user owns the necessary folders:

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

Service Not Starting

Check the logs with:

sudo journalctl -u gitea

This can reveal issues like missing dependencies or misconfigurations.

Port Conflicts

If port 3000 is already in use, modify the ExecStart line in the systemd service file to use a different port, and update your firewall rules accordingly.

Conclusion

By following this guide, you can install Gitea as a systemd service on Ubuntu 24.04 without relying on Docker. This native setup offers a lightweight, reliable, and self-hosted Git solution that integrates seamlessly with your server. At ByteHosting, we are committed to providing the best infrastructure for your development needs. Whether you choose our affordable VPS plans or custom solutions, we’re here to support your hosting journey.

Read more