Gitea is a self-hosted Git platform just like GitLab. But Gitea is more simple, lightweight and easy to configure than GitLab. In this article, I am going to show you how to install and use Gitea on Ubuntu 20.04 LTS. So, let’s get started.

Tested on: Ubuntu 18.04 LTS and Ubuntu 20.04 LTS.

Setting Up Static IP Address:

Before you get started, you should set up a static IP address on your Ubuntu 20.04 LTS machine. If you need any assistance on that, check my article Setting Up Static IP Address on Ubuntu 20.04 LTS.

I have set up a static IP address 192.168.0.11 on my Ubuntu machine where I am installing Gitea. So, make sure to replace it with yours from now on.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Updating APT Package Repository Cache:

Now, update the APT package repository cache with the following command:

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Installing wget:

To download Gitea binary from the command line, you need either wget or curl. In this article, I will use wget.

You can install wget with the following command:

$ sudo apt install wget -y

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Installing Git:

You also need to have git installed on your computer for Gitea to work.

You can install git with the following command:

$ sudo apt install git -y

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Installing and Configuring MySQL for Gitea:

Gitea can work with MySQL, PostgreSQL, SQLite3 and MSSQL databases. In this article, I will configure Gitea to use the MySQL database.

You can install MySQL on your Ubuntu 20.04 LTS machine with the following command:

$ sudo apt install mysql-server mysql-client -y

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

MySQL should be installed.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, login to the MySQL console as root with the following command:

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, type in your MySQL root password and press .

By default, no password is set for the root user. So, if you’re following along, just press .

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

You should be logged in to the MySQL console.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, create a new MySQL user gitea with the password secret with the following SQL statement:

mysql> CREATE USER ‘gitea’ IDENTIFIED BY ‘secret’;

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, create a gitea database for Gitea with the following SQL statement:

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, allow the gitea user full access to the gitea database with the following SQL statement:

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

For the changes to take effect, run the following SQL statement:

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, exit out of the MySQL shell as follows:

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Installing Gitea:

Now, download Gitea binary from the official website of Gitea with the following command:

$ sudo wget -O /usr/local/bin/gitea https://dl.gitea.io/gitea/1.11.4/


gitea-1.11.4-linux-amd64

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Gitea binary is being downloaded.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

At this point, Gitea should be downloaded.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, give execute permission to the Gitea binary /usr/local/bin/gitea with the following command:

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

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, you should be able to access Gitea as shown in the screenshot below.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, create a new user git for Gitea as follows:

$ sudo adduser –system –shell /bin/bash –gecos ‘Git Version Control’


 –group –disabled-password –home /home/git git

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Here, the git repositories will be stored in the HOME directory of the git user /home/git.

The user git should be created.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, create all the required directories for Gitea as follows:

$ sudo mkdir -pv /var/lib/gitea/{custom,data,log}

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, change the user and group of the directories you have just created to git as follows:

$ sudo chown -Rv git:git /var/lib/gitea

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, set correct permissions to the /var/lib/gitea/ directory as follows:

$ sudo chmod -Rv 750 /var/lib/gitea

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, create a Gitea configuration directory /etc/gitea/ as follows:

$ sudo mkdir -v /etc/gitea

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, change the user to root and group to git of the Gitea configuration directory /etc/gitea/ as follows:

$ sudo chown -Rv root:git /etc/gitea

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, set correct permissions to the /etc/gitea/ directory as follows:

$ sudo chmod -Rv 770 /etc/gitea

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Configuring Gitea Service:

Now, you have to create a systemd service file gitea.service for Gitea in the /etc/systemd/system/ directory.

To create a service file for Gitea, run the following command:

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

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, type in the following lines in the gitea.service file.

[Unit]

Description=Gitea (Git with a cup of tea)

After=syslog.target

After=network.target

Requires=mysql.service

[Service]

LimitMEMLOCK=infinity

LimitNOFILE=65535

RestartSec=2s

Type=simple

User=git

Group=git

WorkingDirectory=/var/lib/gitea/

ExecStart=/usr/local/bin/gitea web –config /etc/gitea/app.ini

Restart=always

Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

CapabilityBoundingSet=CAP_NET_BIND_SERVICE

AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]

WantedBy=multi-user.target

Once you’re done, save the gitea.service file by pressing X followed by Y and .

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, start the gitea service with the following command:

$ sudo systemctl start gitea

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

As you can see, the gitea service is running.

$ sudo systemctl status gitea

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, add gitea service to the system startup of your Ubuntu 20.04 LTS machine. So, it will automatically start on boot.

$ sudo systemctl enable gitea

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Initial Configuration of Gitea:

Now, you have to configure Gitea from the web browser.

First, find the IP address of your Ubuntu 20.04 LTS machine as follows:

In my case, the IP address is 192.168.0.11. It will be different for you. So, replace it with yours from now on.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, open a web browser and visit http://192.168.0.11:3000. You should see the following page.

NOTE: Gitea runs on port 3000 by default.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, click on any of the Register or Sign In link.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Gitea initial configuration page should be displayed. You have to configure Gitea from here.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Type in your MySQL database information in the Database Settings section. Make sure that the database settings are correct before moving on.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

In the General Settings section, you can configure many things of Gitea.

You can change the default site title (Site Title), the directory where git repositories will be stored (Repository Root Path), the Git LFS Root Path, Gitea run user (Run As Username), Gitea Log Path, Gitea port (Gitea HTTP Listen Port), HTTP/HTTPS clone URL (Gitea Base URL), SSH clone URL (SSH Server Domain), and SSH clone port (SSH Server Port).

You can pretty much leave everything the default if you want. But, make sure to change the SSH Server Domain and Gitea Base URL to a Fully Qualified Domain Name (FQDN) or the IP address of your Ubuntu machine. Also, adjust the SSH Server Port if you have changed the SSH port on your Ubuntu machine.

I have changed the SSH Server Domain to 192.168.0.11, Gitea HTTP Listen Port to 80 and the Gitea Base URL to http://192.168.0.11/.

NOTE: If you set Gitea HTTP Listen Port to 80, then you don’t have to include port 80 in the Git Base URL section. You can just set http://192.168.0.11/ as your Git Base URL.

But if you use any port like 8080, then you should include it in the Git Base URL. i.e. http://192.168.0.11:8080/

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

There are also optional Email Settings (if you want to send email from your Gitea server), Server and Third-Party Service Settings (for Third-part service integration with Gitea) and Administrator Account Settings (for creating a Gitea administrator account). Just click on the arrow to expand these if you want.

I am not going to configure these in this article.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Gitea Email Settings.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Gitea Server and Third-Party Service Settings.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Gitea Administrator Account Settings.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Once you’re done setting up Gitea, click on Install Gitea.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Gitea should be installed and your browser should redirect you to the Gitea homepage.

If you have changed the Gitea HTTP port (as I did), then you may see the following error message. It’s very easy to fix.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

To fix that, all you have to do is to restart the gitea service with the following command:

$ sudo systemctl restart gitea

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Once you restart the gitea service, you should be able to access Gitea from the web browser as usual.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Using Gitea:

In this section, I am going to show you how to use Gitea.

First, click on Register.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, type in your personal information and click on Register Account to create a new Gitea account.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

A new Gitea account should be created and you should be logged in to your account.

Now, click on the button to create a new Git repository.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Type in a Repository Name and other repository information. Then, click on Create Repository.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

A new Git repository (test in my case) should be created as you can see in the screenshot below.

Gitea should also instruct you on how you use this repository.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, create a directory test/ on your computer and navigate to that directory as follows:

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, create a new Git repository in the test/ directory as follows:

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, create a simple README.md file as follows:

$ echo “Hello World from LinuxHint” > README.md

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, make a commit as follows:

$ git add -A


$ git commit -m ‘initial commit’

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, add the Gitea repository (test in my case) you have just created as a remote repository as follows:

$ git remote add origin http://192.168.0.11/shovon/test.git

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, push the changes to the remote Gitea repository as follows:

$ git push -u origin master

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, type in your Gitea username and press .

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Now, type in your Gitea password and press .

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Your git repository should be uploaded to your Gitea server.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

As you can see, the changes are applied to the test Git repository on my Gitea server.

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

So, that’s how you install and use Gitea on Ubuntu 20.04 LTS. Thanks for reading this article.

About the author

Installing Gitea – A self-hosted Git Server on Ubuntu 20.04 LTS git ubuntu

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.