Jun 22, 2023 5 min read

How to Install Gitea on Ubuntu 22.04

Install Gitea on Ubuntu 22.04 with our step-by-step tutorial. It's an open-source platform for hosting and managing Git repositories.

Install Gitea on Ubuntu 22.04
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install Gitea on Ubuntu 22.04 OS, let's briefly understand – What is Gitea?

Gitea is a lightweight, open-source platform for hosting and managing Git repositories. It provides a user-friendly interface and essential features like code collaboration, issue tracking, and pull requests.

With its easy installation process and low system requirements, Gitea is suitable for individuals, small teams, and organizations. This self-hosted Git service offers a seamless experience for version control and code management, making it a popular choice for developers and software projects of all sizes.

In this tutorial, you'll install Gitea on Ubuntu 22.04. We will also address a few FAQ's on how to install Gitea on Ubuntu 22.04.

Advantages of Gitea

  1. Lightweight and easy to install: Gitea is a lightweight platform that can be quickly installed, making it accessible for individuals and teams.
  2. User-friendly interface: Gitea provides a user-friendly interface, making it easy for developers to navigate and manage their Git repositories.
  3. Code collaboration: Gitea enables seamless code collaboration, allowing developers to work together efficiently on projects.
  4. Issue tracking: Gitea offers built-in issue tracking functionality, simplifying project management and bug tracking.
  5. Pull requests: Gitea supports pull requests, making it convenient for developers to review and merge code changes in a controlled manner.

Prerequisites to Install Gitea on Ubuntu 22.04

  • Ubuntu 22.04 64-bit Operating System
  • A user account with sudo privileges
  • Command-line/terminal
  • SQLite/PostgreSQL/MySQL/MariaDB as database backends

Step 1 – Install SQLite

We are using SQLite in this tutorial. If it's not installed on your Ubuntu system, you can do it by entering the following commands as sudo user:

 sudo apt update
 sudo apt install sqlite3

Step 2 – Install Git

After that, install Git on your server with the following commands:

 sudo apt update
 sudo apt install git

Step 3 – Verify installation by displaying the Git version

 git --version

The output would look something like this:

Output

git version 2.17.1

Step 4 – Create a Git User

You will now be creating a new Gitea user which will run the Gitea application by typing the following:

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

The above command will create a new user and group named git, and set the home directory to /home/git . The output will look something like:

Output 

Adding system user `git' (UID 231) ...
Adding new group `git' (GID 156) ...
Adding new user `git' (UID 231) with group `git' ...
Creating home directory `/home/git' ...

Step 5 – Download Gitea Binary

After that, you need to download the Gitea Binary in the /tmp directory using the following command:

VERSION=1.10.2
sudo wget -O /tmp/gitea https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-linux-amd64

You can run the gitea binary from any location. We’ll move the binary to the /usr/local/bin directory:

 sudo mv /tmp/gitea /usr/local/bin

After that, you need to make the binary executable using the following command:

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

Now we'll run the following commands to create the directories and set the required permissions:

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

The directory structure which we have used in the above commands is recommended by the Official Gitea documentation.

The /etc/gitea directory permissions are set to 770 so that the installation wizard can create the configuration file. Upon completion of the installation, we'll set more permissions.

Step 6 – Create a Systemd Unit File

Gitea usually provides a Systemd unit file that is already configured that matches our setup.

After that, you need to download the file to the /etc/systemd/system/ directory by typing the following command:

sudo wget https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service -P /etc/systemd/system/

When you are done, enable and start the Gitea service.

sudo systemctl daemon-reload
sudo systemctl enable --now gitea

Verify if the service is started successfully.

Output

gitea.service - Gitea (Git with a cup of tea)
   Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-01-04 21:27:23 UTC; 3s ago
 Main PID: 14804 (gitea)
    Tasks: 9 (limit: 1152)
   CGroup: /system.slice/gitea.service
           └─14804 /usr/local/bin/gitea web --config /etc/gitea/app.ini
...

Step 7 – Configure Gitea

Now that Gitea is downloaded and running, it is time for us to finalize the installation using the web interface.

If you have a UFW firewall running on your server, you’ll need to open the Gitea port.

To allow traffic on port 3000, enter the following command:

sudo ufw allow 3000/tcp

After that, open your browser, type http://YOUR_DOMAIN_IR_IP:3000, and do the following configuration:

Database Settings:

  • Database Type: SQLite3
  • Path: Use the path, /var/lib/gitea/data/gitea.db

Application General Settings:

  • Site Title: Enter the name of your organization
  • Run As Username: git
  • Gitea HTTP Listen Port: 3000
  • Repository Root Path: Leave the default /home/git/gitea-repositories
  • Git Large File Storage Root Path: Skip the default /var/lib/gitea/data/lfs
  • Gitea Base URL: Use HTTP and your domain or server IP address
  • SSH Server Domain: Enter your domain or server IP address
  • SSH Port: 22, change it if SSH is listening on other Port
  • Log Path: Leave the default /var/lib/gitea/log
ℹ️
You can change the settings based on your need by just editing them in the Gitea Configuration file.

Once done, hit the “Install Gitea” button. The installation generally takes less than a minute. When it is done, you will be redirected to the login page.

After that, click on the “Sign up now” link. The first registered user is added to the Admin group by default.

As a precaution, change the permissions of the Gitea configuration file to read-only, using:

sudo chmod 750 /etc/gitea

Voila! Your Gitea is installed and configured on the Ubuntu 22.04 machine successfully.

FAQs to Install Gitea on Ubuntu 22.04

Does Gitea support a database backend?

Yes, Gitea supports several database backends, including SQLite, MySQL, and PostgreSQL. You can choose the one that best suits your needs during the installation process.

Can I use Gitea with an existing web server like Nginx?

Yes, Gitea can be integrated with Nginx or other web servers as a reverse proxy. The official documentation provides detailed instructions on how to configure this setup.

Is it possible to set up HTTPS (SSL/TLS) for Gitea?

Absolutely! Gitea can be configured to use HTTPS. You can obtain an SSL/TLS certificate and configure your web server accordingly to enable secure communication with Gitea.

How can I back up my Gitea instance on Ubuntu 22.04?

Gitea provides a built-in backup feature. You can use the command-line interface or the web interface to create backups of your repositories, configuration, and database regularly.

Can I customize the look and feel of Gitea?

Yes, Gitea allows you to customize its appearance. You can modify the logo, favicon, and other visual elements to match your desired branding or design preferences.

Does Gitea support LDAP or Active Directory integration for user authentication?

Yes, Gitea supports LDAP and Active Directory integration. You can configure Gitea to authenticate users against your LDAP or Active Directory server, enabling centralized user management.

Can I migrate my existing Git repositories to Gitea?

Absolutely! Gitea provides import functionality that allows you to migrate repositories from other Git hosting platforms or from local repositories on your Ubuntu 22.04 server.

Conclusion

We hope this tutorial helped you understand how to install Gitea on your Ubuntu 22.04. Click here to know more about Gitea and its features.

If you have any concerns or queries regarding Gitea installation on Ubuntu 22.04, leave a comment below, and we will respond without fail.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.