Atlantic.Net Blog

How to Install Gitea Code Hosting Service on RockyLinux 8

Gitea is a free and open-source Git repository hosting platform written in the Go language. It allows you to work with version control software with other features including issue tracking, pull requests, user management, notifications, and more. It is very similar to GitHub, Bitbucket, and Gitlab, and can run on Linux, macOS, Windows, and ARM. If you are looking for an open-source, lightweight, and self-hosted code hosting platform, then Gitea is the best choice for you.

In this post, we will show you how to install Gitea on Rocky Linux 8.

Step 1 – Install and Configure MariaDB Database

Gitea uses a MariaDB, MySQL, or PostgreSQL as a database backend, so one of the database software solutions must be installed on your server.

First, install all the required dependencies using the following command:

dnf install git unzip gnupg2 nano wget -y

Once all the dependencies are installed, run the following command to install MariaDB:

dnf install mariadb-server -y

Next, start and enable the MariaDB service using the following command:

systemctl start mariadb
systemctl enable mariadb

Next, you will need to create a database and user for Gitea.

First, log in to the MariaDB shell with the following command:

mysql

Once you are logged in, create a database and user with the following command:

CREATE DATABASE gitea CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
GRANT ALL ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY 'password';

Next, flush the privileges and exit from the MariaDB shell with the following command:

FLUSH PRIVILEGES;
EXIT;

Next, edit the MariaDB configuration file:

nano /etc/my.cnf.d/mariadb-server.cnf

Add the following lines below the line [mysqld]:

innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_default_row_format = dynamic

Save and close the file then restart the MariaDB service to apply the changes:

systemctl restart mariadb

Step 2 – Install and Configure Gitea

First, create a dedicated user to run Gitea using the following command:

useradd --system --shell /bin/bash --comment 'Git Version Control' --create-home --home /home/git  git

Next, download the latest version of the Gitea binary with the following command:

wget https://dl.gitea.io/gitea/1.15.4/gitea-1.15.4-linux-amd64

Next, move the downloaded binary to the system path and set proper permissions:

mv gitea-1.15.4-linux-amd64 /usr/bin/gitea
chmod 755 /usr/bin/gitea

Next, verify the Gitea version using the following command:

gitea --version

You should get the following output:

Gitea version 1.15.4 built with GNU Make 4.1, go1.16.9 : bindata, sqlite, sqlite_unlock_notify

Next, you will need to create a directory structure for Gitea.

You can create it with the following commands:

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

Step 3 – Create a Systemd Service File for Gitea

Next, you will need to create a systemd service file to manage the Gitea service:

nano /etc/systemd/system/gitea.service

Add the following lines:

[Unit]
 Description=Gitea
 After=syslog.target
 After=network.target
 After=mysql.service

 [Service]
 RestartSec=2s
 Type=simple
 User=git
 Group=git
 WorkingDirectory=/var/lib/gitea/
 ExecStart=/usr/bin/gitea web -c /etc/gitea/app.ini
 Restart=always
 Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

 [Install]
 WantedBy=multi-user.target

Save and close the file, then reload the systemd daemon with the following command:

systemctl daemon-reload

Next, start the Gitea service and enable it to start at system reboot:

systemctl start gitea
systemctl enable gitea

You can now check the status of Gitea using the following command:

systemctl status gitea

You should see the following output:

● gitea.service - Gitea
   Loaded: loaded (/etc/systemd/system/gitea.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-10-12 14:20:12 UTC; 13s ago
 Main PID: 8998 (gitea)
    Tasks: 8 (limit: 23695)
   Memory: 123.3M
   CGroup: /system.slice/gitea.service
           └─8998 /usr/bin/gitea web -c /etc/gitea/app.ini

Oct 12 14:20:12 RockyLinux8 gitea[8998]: 2021/10/12 14:20:12 cmd/web.go:102:runWeb() [I] Starting Gitea on PID: 8998
Oct 12 14:20:12 RockyLinux8 gitea[8998]: 2021/10/12 14:20:12 ...s/setting/setting.go:569:NewContext() [W] Custom config '/etc/gitea/app.ini' n>
Oct 12 14:20:12 RockyLinux8 gitea[8998]: 2021/10/12 14:20:12 ...s/install/setting.go:21:PreloadSettings() [I] AppPath: /usr/bin/gitea
Oct 12 14:20:12 RockyLinux8 gitea[8998]: 2021/10/12 14:20:12 ...s/install/setting.go:22:PreloadSettings() [I] AppWorkPath: /var/lib/gitea
Oct 12 14:20:12 RockyLinux8 gitea[8998]: 2021/10/12 14:20:12 ...s/install/setting.go:23:PreloadSettings() [I] Custom path: /var/lib/gitea/cust>
Oct 12 14:20:12 RockyLinux8 gitea[8998]: 2021/10/12 14:20:12 ...s/install/setting.go:24:PreloadSettings() [I] Log path: /var/lib/gitea/log
Oct 12 14:20:12 RockyLinux8 gitea[8998]: 2021/10/12 14:20:12 ...s/install/setting.go:25:PreloadSettings() [I] Preparing to run install page
Oct 12 14:20:12 RockyLinux8 gitea[8998]: 2021/10/12 14:20:12 ...s/install/setting.go:28:PreloadSettings() [I] SQLite3 Supported
Oct 12 14:20:13 RockyLinux8 gitea[8998]: 2021/10/12 14:20:13 cmd/web.go:196:listen() [I] Listen: http://0.0.0.0:3000
Oct 12 14:20:13 RockyLinux8 gitea[8998]: 2021/10/12 14:20:13 ...s/graceful/server.go:62:NewServer() [I] Starting new Web server: tcp:0.0.0.0:3>

By default, Gitea listens on port 3000. You can verify it using the following command:

ss -antpl | grep 3000

You should get the following output:

LISTEN 0      128                *:3000            *:*    users:(("gitea",pid=8998,fd=6))

Step 4 – Access Gitea Web Interface

Now, open your web browser and type the URL http://your-server-ip:3000 to access the Gitea web interface. You will get the following screen:
Gitea Database Settings

Gitea General Settings

Gitea Port Settings

Gitea Admin Settings
Provide your Gitea repository name, run as username, listen port, base URL, admin username, and password and click on the Install Gitea button. Once the installation has been completed, you will be redirected to the Gitea dashboard:
Gitea Dashboard Settings

Conclusion

In this guide, you learned how to install the Gitea code hosting platform on RockyLinux 8. You can now start implementing Gitea in your development environment to manage and track your code. Give it a try on your dedicated server from Atlantic.Net!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year