How to Install Gitea on AlmaLinux 9

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

  • AlmaLinux 9 installed
  • Full SSH root access.
  • Gitea supports the following databases.
    • SQLite
    • PostgreSQL
    • MySQL
    • MariaDB
    • TiDB
    • MSSQL

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, you will first need to install epel-release and then SQLite can be installed.

dnf install epel-release

dnf install sqlite

To check the version.

[root@server ~]# sqlite3 --version
3.34.1 2021-01-20 14:10:07 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ealt1

Installing Gitea

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

To Install the Gitea using the following command.

dnf install git

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

git --version

Output:

[root@server ~]# git version
git version 2.31.1

Add the user that will run the Gitea application.

[root@server ~]# adduser --system --shell /bin/bash --comment 'Git Version Control' --create-home --home /home/git 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.16.8. If there is a newer version available on the link above, change the VERSION variable before using the following command.

dnf install wget

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

Output:

[root@server ~]# wget -O /tmp/gitea https://dl.gitea.io/gitea/1.16.8/gitea-1.16.8-linux-amd64
--2022-05-30 20:31:54--  https://dl.gitea.io/gitea/1.16.8/gitea-1.16.8-linux-amd64
Resolving dl.gitea.io (dl.gitea.io)... 104.26.0.119, 104.26.1.119, 172.67.74.188, ...
Connecting to dl.gitea.io (dl.gitea.io)|104.26.0.119|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 107572296 (103M) [application/octet-stream]
Saving to: ‘/tmp/gitea’

/tmp/gitea                     100%[====================================================>] 102.59M  9.62MB/s    in 8.6s

2022-05-30 20:32:03 (11.9 MB/s) - ‘/tmp/gitea’ saved [107572296/107572296]

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

mv /tmp/gitea /usr/local/bin

Make the binary executable.

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 give the file permission using the following command.

restorecon -rv /usr/local/bin/gitea

To create a Systemd Unit File.

Download the file to the "/etc/systemd/system/" directory using the following 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@server ~]# systemctl status gitea
● gitea.service - Gitea (Git with a cup of tea)
     Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: disabled)
     Active: active (running) since Mon 2022-05-30 18:31:56 CEST; 2h 3min ago
   Main PID: 4532 (gitea)
      Tasks: 7 (limit: 5925)
     Memory: 241.1M
        CPU: 19.328s
     CGroup: /system.slice/gitea.service
             └─4532 /usr/local/bin/gitea web --config /etc/gitea/app.ini

Configure Gitea

To allow port using the following command.

firewall-cmd --permanent --zone=public --add-port=3000/tcp
firewall-cmd --reload

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

Done.