Site icon DesignLinux

How to Install Gitea on Ubuntu 20.04

How to Install Gitea on Ubuntu 20.04

Gitea is an open source, lightweight and self-hosted git platform written in Go. It’s similar to Gitlab, but probably the easiest, fastest, and straightforward to setting up. It includes rich features like issues and time tracking, repository branching, file locking and tagging, merging, and much more. In this article, we will show you how to install and configure Gitea on Ubuntu 20.04.

Prerequisites

An Ubuntu 20.04 system and access root or user with sudo privileges.

Installing Gitea

Peform the following steps to install Gitea on your Ubuntu 20.04 system.

Step 1 – Update the package list

Before starting, you should update the all installed packages on your Ubuntu system. Run the following commands:

sudo apt-get update -y
sudo apt-get upgrade -y

Step 2 – Install Git and Create Git User

At first, we need to in install git on your server. Run the below command to install git package on Ubuntu.

sudo apt install git

Verify the installation by displaying the Git version:

git --version
git version 2.25.1

After that, we need to create a new system user which will run the Gitea application:

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

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

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

Next, step is to install MariaDB and configure.

Step 3: Install and Configure MariaDB

Gitea requires a database server to store it content. Gitea supports SQLite, PostgreSQL , and MySQL / MariaDB as database backends. Run the following command to install MariaDB on your Ubuntu system:

sudo apt-get install mariadb-server mariadb-client

After install complete, connect the MariaDB shell by typing:

sudo mysql

Once connected, enable the Innodb table using the following command:

SET GLOBAL innodb_file_per_table = ON;

Now, create a database and use for Gitea with the following command:

CREATE DATABASE gitea;
CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'securepassword';

You should grant all the privileges to gitea database and set character set to utf8mb4:

GRANT ALL ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY 'securepassword' WITH GRANT OPTION;
ALTER DATABASE gitea CHARACTER SET = utf8mb4 COLLATE utf8mb4_unicode_ci;

Flush the privileges an exit from the MariaDB with the following command:

FLUSH PRIVILEGES;
EXIT;

Next, edit the MariaDB default configuration file and tweak some settings:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add the following lines inside [mysqld] section:

innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_default_row_format = dynamic

Save the file then restart the MariaDB service to apply the changes:

sudo systemctl restart mariadb

Step 3 – Installing Gitea Packages

Download the latest binary for your architecture from the Gitea Download page. Currently, latest version is 1.14.2 at the time of writing this tutorial. You should check and change the latest version if available.

Run the below command using wget to download the Gitea binary in /tmp directory:

sudo wget -O /tmp/gitea https://dl.gitea.io/gitea/1.14.2/gitea-1.14.2-linux-amd64

Move downloaded file into the /usr/local/bin directory and make it executable by typing:

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

Run the commands below to create the directories and set the required permissions and ownership:

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 4 – Create a Systemd Unit File

We need to create systemd unit file to run Gitea as a systemd service. Simply download the sample systemd unit file to the /etc/systemd/system directory by typing:

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

It’s already configure so no need to edit this file.

Enable and start the Gitea service:

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

Run the below command to check Gitea status:

sudo systemctl status gitea
● gitea.service - Gitea (Git with a cup of tea)
     Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-05-21 05:32:04 UTC; 7s ago
   Main PID: 22581 (gitea)
      Tasks: 6 (limit: 470)
     Memory: 101.6M
     CGroup: /system.slice/gitea.service
             └─77781 /usr/local/bin/gitea web --config /etc/gitea/app.ini
...

Step 5 – Configure Gitea

Now we need to finalize the installation through the web interface. By default, Gitea listens on port 3000 on all network interfaces.

If your server is secured with UFW firewall, you’ll need to open the Gitea port to allow traffic on port 3000. Execute the following command to allow port:

sudo ufw allow 3000/tcp

Next, Open your browser, type http://YOUR_DOMAIN_IR_IP:3000, and you will get a screen similar to the following:

Also, setup the backend admin account:

That’s it. You can now login and start use of Gitea.

Conclusion

Congratulations! you have successfully installed Gitea on Ubuntu 20.04 system. Visit the Gitea documentation page to learn more about Gitea configuration.

If you have questions, feel free to leave a comment below.

Exit mobile version