How to Install Gitea on Ubuntu 20.04

Gitea is an open-source forge software package for hosting software development version control using Git as well as other collaborative features like bug tracking, wikis, and code review.

Prerequisites

  • Full SSH root access or a user with Sudo privileges is required.
  • Gitea supports the following databases.
    • SQLite
    • PostgreSQL
    • MySQL
    • MariaDB

In our guide below, we’ll use SQLite as the database for Gitea. You can pick any of the supported databases in your installation as needed.

To Install SQLite using the following command.

apt install sqlite3

To check the version.

sqlite3 --version

Output:

root@vps:~# sqlite3 --version
3.31.1 2020-01-27 19:55:54 3bfa9cc97da10598521b342961df8f5f68c7388fa117345eeb516eaa837balt1

Installing Gitea

Gitea is a painless self-hosted Git service. With features similar to ones in GitHub, Bitbucket, or GitLab.

Check for system updates and install them.

apt update

apt upgrade

To Install the Gitea using the following command.

apt install git

To check the version of Git, run the following command.

git --version

Output:

root@vps:~# git --version
git version 2.25.1

Add the user that will run the Gitea application.

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

Output:

root@vps:~# adduser --system --group --disabled-password --shell /bin/bash --home /home/git --gecos 'Git Version Control' git
Adding system user `git' (UID 113) ...
Adding new group `git' (GID 117) ...
Adding new user `git' (UID 113) with group `git' ...
Creating home directory `/home/git' ...

Download the Gitea binary.

Download the Gitea binary from download page and make it executable.

At the time of this article, the latest Gitea version is 1.15.3. If there is a newer version available on the link above, change the VERSION variable before using the following command.

apt install wget

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

Output:

root@vps:~# wget -O /tmp/gitea https://dl.gitea.io/gitea/1.15.3/gitea-1.15.3-linux-amd64
--2021-09-25 16:33:19--  https://dl.gitea.io/gitea/1.15.3/gitea-1.15.3-linux-amd64
Resolving dl.gitea.io (dl.gitea.io)... 172.67.186.211, 104.21.60.7, 2606:4700:3034::ac43:bad3, ...
Connecting to dl.gitea.io (dl.gitea.io)|172.67.186.211|:443... connected.
HTTP request sent, awaiting response... 307 Temporary Redirect
Location: https://storage.gitea.io/gitea-artifacts/gitea/1.15.3/gitea-1.15.3-linux-amd64?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=SU5ZZ3Q6D6AFIQSCOO65%2F20210925%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210925T163319Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=b263a338277a17617ad7cf7d1f5db68c74046d1d60c0f96d17990e4b935da105 [following]

Move the Gitea binary file to "/usr/local/bin".

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

Make the binary executable.

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

Create the directory structure and set the required permissions and ownership.

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

To create a Systemd Unit File.

Download the file to the "/etc/systemd/system/" directory using the following the command.

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

To reload a Gitea service.

systemctl daemon-reload

To enable a Gitea service.

systemctl enable --now gitea

Output:

root@vps:~# systemctl enable --now gitea
Created symlink /etc/systemd/system/multi-user.target.wants/gitea.service → /etc/systemd/system/gitea.service.

To check the status of the Gitea service.

systemctl status gitea

Output:

root@vps:~#     systemctl status gitea
● gitea.service - Gitea (Git with a cup of tea)
     Loaded: loaded (/etc/systemd/system/gitea.service; enable>
     Active: active (running) since Sat 2021-09-25 16:37:06 UT>
   Main PID: 65991 (gitea)
      Tasks: 9 (limit: 3399)
     Memory: 119.7M
     CGroup: /system.slice/gitea.service
             └─65991 /usr/local/bin/gitea web --config /etc/gi>

Configure Gitea

To allow port using the following command.

ufw allow 3000/tcp

Navigate to your browser. http://yourserver-ip-address:3000 to access the Gitea application.

Follow the on-screen instructions to complete the Gitea setup. Click on Register to start the database initialization.

Database Settings:

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

image

Application General Settings:

  • Site Title: Enter username.
  • Repository Root Path: keep the default /home/git/gitea-repositories.
  • Git LFS Root Path: keep the default /var/lib/gitea/data/lfs.
  • Run As Username: git
  • SSH Server Domain: Enter your domain name or your IP address.
  • SSH Port: 22, change it if SSH is listening on other Port
  • Gitea HTTP Listen Port: 3000
  • Gitea Base URL: Use http and your domain or server IP address.
  • Log Path: Leave the default /var/lib/gitea/log

Click on Install to Install Gitea.

image

Once the installation is completed then create the first user. Open http://yourip:3000/user/sign_up in a web browser and fill in the required details.

image

Once the form has been submitted, you are logged into your Gitea account.

image

Upgrading Gitea

To upgrade to a new version first stop the Gitea service.

To stop the Gitea service.

systemctl stop gitea

Download the Gitea binary from download page.

At the time of this article, the latest Gitea version is 1.15.3. If there is a newer version available on the link above, change the VERSION variable before using the following command.

VERSION=<THE_LATEST_GITEA_VERSION>

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

Move the Gitea binary file to "/usr/local/bin" and make the binary executable.

mv /tmp/gitea /usr/local/bin

chmod +x /usr/local/bin/gitea

To restart the Gitea service.

systemctl restart gitea

Done.


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS