How to Install Gogs Git on RockyLinux 8

This tutorial will walk you through the steps necessary to install the Gogs self-hosted Git service on an RockyLinux 8 server. The Gogs project, written in Go, aims to create a simple, stable, and extensible self-hosted Git service with a simple setup process.

Gogs performs admirably and is extremely light. It uses very little RAM and CPU power. 

Checkout the Gogs Project at https://gogs.io/ for more information.

Prerequisites

  • Full SSH root access or a user with sudo privileges is required.
  • Gogs supports the following databases.
    • SQLite3
    • PostgreSQL
    • MySQL
    • MariaDB

First, check for any pending system upgrade

Let's update software packages first. To perform updates, run the following command:

dnf update

Install MariaDB Database Server

Use the below command to install MariaDB.

dnf install mariadb-server

Now, start the MariaDB service

systemctl start mariadb
systemctl enable mariadb
systemctl status mariadb

Check the status of MariaDB service.

[root@vps ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor pr>
   Active: active (running) since Sat 2023-03-11 12:57:52 UTC; 4s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 38150 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, s>
  Process: 38012 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service>
  Process: 37987 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, sta>
 Main PID: 38119 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 17817)
   Memory: 83.3M
   CGroup: /system.slice/mariadb.service
           └─38119 /usr/libexec/mysqld --basedir=/usr

Mar 11 12:57:48 vps.server.com systemd[1]: Starting MariaDB 10.3 database serve>
Mar 11 12:57:48 vps.server.com mysql-prepare-db-dir[38012]: Initializing MariaD>
Mar 11 12:57:52 vps.server.com mysqld[38119]: 2023-03-11 12:57:52 0 [Note] /usr>
Mar 11 12:57:52 vps.server.com systemd[1]: Started MariaDB 10.3 database server.
lines 1-19/19 (END)

Secure the Mysql Installation with the below command,

mysql_secure_installation

Output:

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

Login to Mysql as root user,

mysql -u root -p

Enable global variables as shown below,

SET GLOBAL innodb_file_per_table = ON;

Create a database called gogs which will be used for this project,

CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Create a user and grant all the privileges of the gogs database,

GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost' IDENTIFIED BY "StrongPassword";

Replace "StrongPassword" with an actual password that is long and strong.

FLUSH PRIVILEGES;
EXIT

Download and Install Gogs from GitHub

Use curl to download the Gogs file from their official github repository.

curl -s https://api.github.com/repos/gogs/gogs/releases/latest | grep browser_download_url | grep '\linux_amd64.zip' | cut -d '"' -f 4 | wget -i -

Unzip the downloaded Gogs file.

unzip  gogs_*_linux_amd64.zip

Install the packages of git using dnf command

dnf install git

Create a new user called git,

adduser git

Create a dedicated logs directory for it's user,

mkdir /var/log/gogs

Permit created directory access to the added user,

chown -R git:git /var/log/gogs/

Move the Gogs binary file to /home/git,

mv gogs /home/git/

Change the permission of the site directory.

chown -R git:git /home/git/

Next,Enable the firewalld for Port 3001

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

Switch to git user that was created earlier,

su -i git

Then change the directory to where gogs is located,

cd /home/git/gogs/

Then, run the gogs with the web option:

./gogs web -port 3001

Configure Gogs

Navigate to your browser and load the server's IP address or the domain name with 3001 port.

http://server-ip-address:3001 and you will see the Gogs installation screen.

In Database Settings we'll first enter the Database information that was created earlier.

image

Next, In Application General Settings

  • Application Name - enter the Project name of your choice.
  • Run User - will be the new user that was added earlier, git.
  • Domain - enter the Domain name that should be associated with the application. If you do not have any domain, use localhost.
  • Application URL - enter the IP address of the server or the Domain name with the port to be used.

    Do not use localhost in Application URL.

  • Log Path - enter the directory path that was created earlier, /var/log/gogs.

image

In Optional Settings,

  • Enable or Disable the required settings that goes with your application usage.
  • Create an Admin Account which you will be using as first user with Admin privileges.

image

Now click on Install Gogs button to start the installation. Once the installation is complete, you will be redirected to login screen.

Login with the Admin user that was just created in the last step.

image

This concludes the Installation and Gogs on Rockylinux 8