Table of Contents
In this article, I will take you through 10 Simple and Best Steps to Install Gitea on Ubuntu 20.04. If you are looking for the the easiest, fastest, and most painless way of setting up a self-hosted Git service, then probably Gitea is the best option you can use.
What is Gitea
Gitea is a painless self-hosted Git service. It is similar to GitHub, Bitbucket, and GitLab. Gitea is a fork of Gogs.
Steps to Install Gitea on Ubuntu 20.04
Also Read: How to Install JUnit on Ubuntu 20.04 in 4 Practical Steps
Step 1: Prerequisites
a) You should have a running Ubuntu 20.04
Server.
b) You should have sudo or root access to run privileged commands.
c) You should have wget
utility installed in your Server.
Step 2: Update Your System
Let's first synchronize all the installed packages with the latest updates available on Ubuntu Repository using apt-get update
command as shown below.
root@localhost:~# apt-get update Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:3 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB] Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] Get:5 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [481 kB] Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [990 kB] Get:7 http://in.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [224 kB] Get:8 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [274 kB] Get:9 http://in.archive.ubuntu.com/ubuntu focal-updates/main DEP-11 48x48 Icons [57.6 kB] Get:10 http://in.archive.ubuntu.com/ubuntu focal-updates/main DEP-11 64x64 Icons [90.7 kB] Get:11 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [13.4 kB] Get:12 http://in.archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [226 kB] Get:13 http://in.archive.ubuntu.com/ubuntu focal-updates/restricted amd64 c-n-f Metadata [436 B] Get:14 http://in.archive.ubuntu.com/ubuntu focal-updates/universe i386 Packages [574 kB] Get:15 http://in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [778 kB] Get:16 http://in.archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [167 kB]
Step 3: Install Git
In the very first step, you need to install git client tool using apt-get install git
command as shown below.
root@localhost:~# apt-get install git Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: git-man liberror-perl Suggested packages: git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn The following NEW packages will be installed: git git-man liberror-perl 0 upgraded, 3 newly installed, 0 to remove and 111 not upgraded. Need to get 5,468 kB of archives. After this operation, 38.4 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://in.archive.ubuntu.com/ubuntu focal/main amd64 liberror-perl all 0.17029-1 [26.5 kB] Get:2 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 git-man all 1:2.25.1-1ubuntu3.1 [884 kB] Get:3 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 git amd64 1:2.25.1-1ubuntu3.1 [4,557 kB] Fetched 5,468 kB in 2s (2,341 kB/s)
Step 4: Create a Git User
Next step is to create a git
user and a git
group using adduser
utility as shown below.
root@localhost:~# adduser \ > --system \ > --shell /bin/bash \ > --gecos 'Git Version Control' \ > --group \ > --disabled-password \ > --home /home/git \ > git Adding system user `git' (UID 127) ... Adding new group `git' (GID 133) ... Adding new user `git' (UID 127) with group `git' ... Creating home directory `/home/git' ...
Step 5: Download Gitea Binary
Download latest Gitea Binary package from Download Page. At the time of writing, gitea-1.14.2-linux-amd64
is the latest version so we are downloading and saving this package as gitea
in current working directory.
root@localhost:~# wget -O gitea https://dl.gitea.io/gitea/1.14.2/gitea-1.14.2-linux-amd64 --2021-05-30 10:39:01-- https://dl.gitea.io/gitea/1.14.2/gitea-1.14.2-linux-amd64 Connecting to dl.gitea.io (dl.gitea.io)|172.67.186.211|:443... connected. Location: https://storage.gitea.io/gitea-artifacts/gitea/1.14.2/gitea-1.14.2-linux-amd64?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=SU5ZZ3Q6D6AFIQSCOO65%2F20210530%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210530T051159Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=3de65964e5c92fc43f20428815005cf750f151d7dec8d26eb845ad3d6b3d2734 [following] --2021-05-30 10:41:59-- https://storage.gitea.io/gitea-artifacts/gitea/1.14.2/gitea-1.14.2-linux-amd64?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=SU5ZZ3Q6D6AFIQSCOO65%2F20210530%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210530T051159Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=3de65964e5c92fc43f20428815005cf750f151d7dec8d26eb845ad3d6b3d2734 Connecting to storage.gitea.io (storage.gitea.io)|147.75.84.81|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 107969264 (103M) [application/octet-stream] Saving to: ‘gitea’ gitea 100%[============================================================================>] 102.97M 2.85MB/s in 44s 2021-05-30 10:44:55 (2.33 MB/s) - ‘gitea’ saved [107969264/107969264] root@localhost:~# ls -lrt gitea -rwxr-xr-x 1 root root 107969264 May 12 00:44 gitea
To run this package, you need to provide execute permission using chmod +x gitea command as shown below.
root@localhost:~# chmod +x gitea
Along with the main gitea
package, you can also download gitea-1.14.2-linux-amd64.asc
file to verify the GPG Signature.
root@localhost:~# wget https://dl.gitea.io/gitea/1.14.2/gitea-1.14.2-linux-amd64.asc --2021-05-30 10:59:14-- https://dl.gitea.io/gitea/1.14.2/gitea-1.14.2-linux-amd64.asc Resolving dl.gitea.io (dl.gitea.io)... 2606:4700:8d9d:e227:98d7:11e:20df:7b74, 172.67.186.211, 104.21.60.7 Connecting to dl.gitea.io (dl.gitea.io)|172.67.186.211|:443... connected. Location: https://storage.gitea.io/gitea-artifacts/gitea/1.14.2/gitea-1.14.2-linux-amd64.asc?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=SU5ZZ3Q6D6AFIQSCOO65%2F20210530%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210530T053133Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=91b34f0baa58b5513a944d400c667bf6fb4b867e17314a1eff0b11b4c78cc825 [following] --2021-05-30 11:01:33-- https://storage.gitea.io/gitea-artifacts/gitea/1.14.2/gitea-1.14.2-linux-amd64.asc?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=SU5ZZ3Q6D6AFIQSCOO65%2F20210530%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210530T053133Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=91b34f0baa58b5513a944d400c667bf6fb4b867e17314a1eff0b11b4c78cc825 Resolving storage.gitea.io (storage.gitea.io)... 2604:1380:2000:c600::5, 147.75.84.81 Connecting to storage.gitea.io (storage.gitea.io)|2604:1380:2000:c600::5|:443... failed: Connection timed out. Connecting to storage.gitea.io (storage.gitea.io)|147.75.84.81|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 833 [text/plain] Saving to: ‘gitea-1.14.2-linux-amd64.asc’ gitea-1.14.2-linux-amd64.asc 100%[============================================================================>] 833 --.-KB/s in 0s 2021-05-30 11:03:44 (3.92 MB/s) - ‘gitea-1.14.2-linux-amd64.asc’ saved [833/833]
Step 6: Verify GPG Signature
To verify GPG Signature, first you need to import Teabot
public key and then verify the gitea downloaded package by using gitea-1.14.2-linux-amd64.asc
file as shown below.
root@localhost:~# gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2 gpg: directory '/root/.gnupg' created gpg: keybox '/root/.gnupg/pubring.kbx' created gpg: /root/.gnupg/trustdb.gpg: trustdb created gpg: key 2D9AE806EC1592E2: public key "Teabot <teabot@gitea.io>" imported gpg: Total number processed: 1 gpg: imported: 1 root@localhost:~# gpg --verify gitea-1.14.2-linux-amd64.asc gitea gpg: Signature made Sunday 09 May 2021 04:04:52 PM IST gpg: using RSA key CC64B1DB67ABBEECAB24B6455FC346329753F4B0 gpg: Good signature from "Teabot <teabot@gitea.io>" [unknown] gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: 7C9E 6815 2594 6888 62D6 2AF6 2D9A E806 EC15 92E2 Subkey fingerprint: CC64 B1DB 67AB BEEC AB24 B645 5FC3 4632 9753 F4B0
Once verified, you can now move gitea
binary to /usr/local/bin
directory using mv gitea /usr/local/bin/
command as shown below.
root@localhost:~# mv gitea /usr/local/bin/
Step 7: Create Directory Structure
Next step is to create gitea directory structure and then change/modify directory ownership using below chmod
and chown
commands.
root@localhost:~# mkdir -p /var/lib/gitea/{custom,data,log} root@localhost:~# chown -R git:git /var/lib/gitea/ root@localhost:~# chmod -R 750 /var/lib/gitea/ root@localhost:~# mkdir /etc/gitea root@localhost:~# chown root:git /etc/gitea root@localhost:~# chmod 770 /etc/gitea
Step 8: Create a Systemd Service
To create a systemd service, you can download Sample systemd service from below link and save it in /etc/systemd/system/gitea.service
using wget
utility as shown below.
root@localhost:~# wget https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/systemd/gitea.service -P /etc/systemd/system/ --2021-05-30 11:19:11-- https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/systemd/gitea.service Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.110.133, 185.199.111.133, ... Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2136 (2.1K) [text/plain] Saving to: ‘/etc/systemd/system/gitea.service’ gitea.service 100%[============================================================================>] 2.09K --.-KB/s in 0s 2021-05-30 11:19:11 (6.43 MB/s) - ‘/etc/systemd/system/gitea.service’ saved [2136/2136]
Reload the daemon using systemctl daemon-reload
command and then enable the service by using systemctl enable --now gitea
command as shown below.
root@localhost:~# systemctl daemon-reload root@localhost:~# systemctl enable --now gitea Created symlink /etc/systemd/system/multi-user.target.wants/gitea.service → /etc/systemd/system/gitea.service.
Now you can start the service using systemctl start gitea
command if not already started and then check the status by using systemctl status gitea
command as shown below.
root@localhost:~# systemctl start gitea root@localhost:~# 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 Sun 2021-05-30 11:34:30 IST; 6s ago Main PID: 5553 (gitea) Tasks: 6 (limit: 2315) Memory: 125.6M CGroup: /system.slice/gitea.service └─5553 /usr/local/bin/gitea web --config /etc/gitea/app.ini May 30 11:34:30 cyberithub-node gitea[5553]: 2021/05/30 11:34:30 ...dules/setting/git.go:101:newGit() [I] Git Version: 2.25.1, Wire Protocol Version 2 Enab> May 30 11:34:30 cyberithub-node gitea[5553]: 2021/05/30 11:34:30 routers/init.go:93:PreInstallInit() [T] AppPath: /usr/local/bin/gitea May 30 11:34:30 cyberithub-node gitea[5553]: 2021/05/30 11:34:30 routers/init.go:94:PreInstallInit() [T] AppWorkPath: /var/lib/gitea May 30 11:34:30 cyberithub-node gitea[5553]: 2021/05/30 11:34:30 routers/init.go:95:PreInstallInit() [T] Custom path: /var/lib/gitea/custom May 30 11:34:30 cyberithub-node gitea[5553]: 2021/05/30 11:34:30 routers/init.go:96:PreInstallInit() [T] Log path: /var/lib/gitea/log May 30 11:34:30 cyberithub-node gitea[5553]: 2021/05/30 11:34:30 routers/init.go:97:PreInstallInit() [T] Preparing to run install page May 30 11:34:30 cyberithub-node gitea[5553]: 2021/05/30 11:34:30 routers/init.go:100:PreInstallInit() [I] SQLite3 Supported May 30 11:34:30 cyberithub-node gitea[5553]: 2021/05/30 11:34:30 cmd/web.go:189:listen() [I] Listen: http://0.0.0.0:3000 May 30 11:34:30 cyberithub-node gitea[5553]: 2021/05/30 11:34:30 ...s/graceful/server.go:55:NewServer() [I] Starting new Web server: tcp:0.0.0.0:3000 on PI> May 30 11:34:30 cyberithub-node gitea[5553]: 2021/05/30 11:34:30 ...s/graceful/server.go:66:func1() [D] Starting server on tcp:0.0.0.0:3000 (PID: 5553)
Step 9: Allow Port
If you are running firewall, then you need to allow TCP Port 3000
from firewall using ufw allow 3000/tcp
command as shown below.
root@localhost:~# ufw allow 3000/tcp Rules updated Rules updated (v6)
Step 10: Configure Gitea
Go to your Browser and open http://localhost:3000
link as shown below. Here you can provide below settings before starting the installation.
Database Type: SQLite3
Path: /var/lib/gitea/data/gitea.db
Site Title: <Your Organization Name>
Repository Root Path: var/lib/gitea/data/gitea-repositories.
Git LFS Root Path: /var/lib/gitea/data/lfs.
Run As Username: git
SSH Server Domain: <Your Domain or IP Address>
SSH Port: 22
Gitea HTTP Listen Port: 3000
Gitea Base URL: By default, it will be localhost
Log Path: /var/lib/gitea/log
Then Click on Install. Once installed, you should now be able to see the Gitea
Home page as shown below.