Hello,
In this week’s feature highlight, we look at Running your own self hosted Git service with Gitea on Rocky Linux 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. It supports self-hosting but also provides a free public first-party instance hosted in China on DiDi’s cloud.
Prerequisites
- Rocky Linux 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 using the following command.
dnf install sqlite3
To check the version.
[root@server ~]# sqlite3 --version
3.34.1 2021-01-20 14:10:07 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ealt1
Install Git
To Install Git
, use 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 Git application.
[root@server ~]# adduser --system --shell /bin/bash --comment 'Git Version Control' --create-home --home /home/git git
Download the Gitea Binary.Gitea is a painless self-hosted Git service. With features similar to ones in GitHub, Bitbucket, or GitLab.
Download the Gitea binary from download page and make it executable.
At the time of this article, the latest Gitea version is 1.16.9. If there is a the newer version is 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.9/gitea-1.16.9-linux-amd64
Output:
[root@server ~]# wget -O /tmp/gitea https://dl.gitea.io/gitea/1.16.9/gitea-1.16.9-linux-amd64
--2022-07-20 18:22:56-- https://dl.gitea.io/gitea/1.16.9/gitea-1.16.9-linux-amd64
Resolving dl.gitea.io (dl.gitea.io)... 172.67.74.188, 104.26.0.119, 104.26.1.119, ...
Connecting to dl.gitea.io (dl.gitea.io)|172.67.74.188|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 107593784 (103M) [application/octet-stream]
Saving to: ‘/tmp/gitea’
/tmp/gitea 100%[===================>] 102.61M 7.40MB/s in 11s
2022-07-20 18:23:08 (8.93 MB/s) - ‘/tmp/gitea’ saved [107593784/107593784]
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@server ~]# 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 Wed 2022-07-20 18:25:45 CEST; 23s ago
Main PID: 14699 (gitea)
Tasks: 8 (limit: 11120)
Memory: 127.1M
CPU: 896ms
CGroup: /system.slice/gitea.service
└─14699 /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
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.
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.
Once the form has been submitted, you are logged into your Gitea account.
Done.