In this tutorial, we will show you how to install Gitea on Ubuntu 20.04 LTS. For those of you who didn’t know, Gitea is a free, open-source, and self-hosted version control system alternative to GitHub and GitLab. Gitea comes with a rich set of features including time tracking, repository branching, issues tracking, file locking, merging, and much more. Gitea can be installed on all popular operating systems like Windows, macOS, Linux, and ARM.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of Gitea on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
Prerequisites
- A server running one of the following operating systems: Ubuntu 20.04, 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Gitea on Ubuntu 20.04 LTS Focal Fossa
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Installing Git and Create Git User.
Run the command to install the Git package on Ubuntu:
sudo apt install git
Confirm Git the installation:
[root@idroot.us ~]# git --version git version 2.25.1
After installing Git, now we create a Git user to run Gitea services:
sudo adduser --system --group --disabled-password --shell /bin/bash --home /home/git --gecos 'Git Version Control' git
Step 3. Installing MariaDB on Ubuntu.
You can install MySQL on your Ubuntu 20.04 LTS system with the following command:
sudo apt install mariadb-server mariadb-client
After the server is installed, the commands below can be used to stop, start, and restart the database services:
sudo systemctl stop mariadb.service sudo systemctl start mariadb.service sudo systemctl restart mariadb.service
Let’s confirm our installation of the MariaDB server on Ubuntu 20.04:
mysql -V
Now we secure MariaDB after installation.
By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation
script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
mysql_secure_installation
Configure it like this:
- Set root password? [Y/n] y - Remove anonymous users? [Y/n] y - Disallow root login remotely? [Y/n] y - Remove test database and access to it? [Y/n] y - Reload privilege tables now? [Y/n] y
To log into MariaDB, use the following command (note that it’s the same command you would use to log into a MySQL database) and create a database for Gitea:
$ mysql -u root -p CREATE DATABASE giteadb; CREATE USER 'giteauser'@'localhost' IDENTIFIED BY 'your_strong_passwd'; GRANT ALL ON giteadb.* TO 'giteauser'@'localhost' IDENTIFIED BY 'your_strong_passwd' WITH GRANT OPTION; FLUSH PRIVILEGES; EXIT;
Step 4. Installing Gitea on Ubuntu 20.04.
Now download the latest version of the Gitea binary from the Git repository. You can download it with the following command:
sudo wget -O /tmp/gitea https://dl.gitea.io/gitea/1.12.5/gitea-1.12.5-linux-amd64
Copy the binary to a global location:
sudo mv /tmp/gitea /usr/local/bin
Make the binary executable:
sudo chmod +x /usr/local/bin/gitea
Next, create the directories and set the required permissions and ownership:
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
Step 4. Create Systemd Service for Gitea.
Now, you have to create a systemd
service file gitea.service
for Gitea in the /etc/systemd/system/
directory:
sudo nano /etc/systemd/system/gitea.service
Paste the content below into the file and save:
[Unit] Description=Gitea (Git with a cup of tea) After=syslog.target After=network.target #After=mysqld.service [Service] # Modify these two values and uncomment them if you have # repos with lots of files and get an HTTP error 500 because # of that ### #LimitMEMLOCK=infinity #LimitNOFILE=65535 RestartSec=2s Type=simple User=git Group=git WorkingDirectory=/var/lib/gitea/ ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini Restart=always Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea # If you want to bind Gitea to a port below 1024 uncomment # the two values below ### #CapabilityBoundingSet=CAP_NET_BIND_SERVICE #AmbientCapabilities=CAP_NET_BIND_SERVICE [Install] WantedBy=multi-user.target
Then, enable and start the Gitea service:
sudo systemctl daemon-reload sudo systemctl enable gitea sudo systemctl start gitea
Step 5. Accessing Gitea Web Interface.
Now, open a web browser and visit http://YOUR_DOMAIN_OR_IP_ADDRESS:3000
. You should see the following page:
Congratulations! You have successfully installed Gitea. Thanks for using this tutorial for installing Gitea on your Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you to check the official Gitea website.