Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

How to Install Gitea on Debian

profile picture
Author
Mohsen Nasiri
Published
2024-10-10
Time to read
4 minutes reading time

About the author- Software Engineer and open-source enthusiast.

Introduction

Gitea is a lightweight, self-hosted Git service that's a great alternative to GitLab or GitHub for smaller teams or personal projects. In this guide, we’ll walk you through installing Gitea on a Debian server.

By the end of this tutorial, you will have a fully operational Gitea instance running on your Debian machine.

Prerequisites

  • A basic understanding of Linux terminal commands.
  • A Debian server with root or sudo privileges.
  • A domain name pointed to your server’s IP (optional, but recommended for SSL).

Step 1 - Update Your Server

The first thing you want to do is ensure your system is up to date.

sudo apt update && sudo apt upgrade -y

Step 2 - Install Required Packages

Gitea needs a few dependencies to run smoothly. Let’s install them:

sudo apt install git mariadb-server mariadb-client curl wget -y
  • git: To manage repositories.
  • mariadb-server: For the database.
  • mariadb-client: To connect to the database.
  • curl and wget: Handy tools for downloading files.

Step 3 - Create a Gitea User

It’s best to create a dedicated user for running Gitea.

sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git

This command creates a user called git without a password, and it assigns a home directory at /home/git.

Step 4 - Configure MariaDB

Let’s set up the MariaDB database that Gitea will use.

  1. Log in to MariaDB as root:

    sudo mysql -u root
  2. Create a new database and user for Gitea:

    CREATE DATABASE gitea CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
    CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'your_password';
    GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;

    Replace 'your_password' with a strong password.

Step 5 - Download and Install Gitea

  1. Download the latest Gitea release:

    wget -O /tmp/gitea https://dl.gitea.com/gitea/1.22.3/gitea-1.22.3-linux-amd64
  2. Move the file to a directory in your PATH and make it executable:

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

Step 6 - Create the Necessary Directories

Gitea needs several directories for configuration and data.

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

Step 7 - Create a Systemd Service

To ensure Gitea runs as a service, let’s create a systemd file.

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

Paste the following into the file:

[Unit]
Description=Gitea
After=syslog.target
After=network.target
Requires=mariadb.service

[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

[Install]
WantedBy=multi-user.target

Save and close the file.

Step 8 - Start and Enable Gitea

Enable Gitea to start on boot and then start the service:

sudo systemctl enable gitea
sudo systemctl start gitea

You can check the status with:

sudo systemctl status gitea

Step 9 - Configure Firewall (Optional)

If you’re using a firewall, make sure to allow Gitea’s default port (3000).

sudo ufw allow 3000/tcp

Step 10 - Access Gitea

Now that everything is set up, you can access your Gitea instance by navigating to your server’s IP or domain followed by port 3000 in your browser.

http://your_domain_or_IP:3000

You’ll be greeted with Gitea’s setup page. Here, you’ll need to enter the database details you created earlier (database name, user, and password). Follow the on-screen instructions to complete the setup.

Conclusion

Congratulations! You’ve successfully installed Gitea on your Debian server. You now have a self-hosted Git service ready to use for your projects. Be sure to secure your instance and set up a domain name with SSL for production use.

License: MIT
Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue
Try Hetzner Cloud

Get 20€ free credit!

Valid until: 31 December 2024 Valid for: 3 months and only for new customers
Get started
Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more