How To Install Gogs on Rocky Linux 9
Gogs is a self-hosted Git service that provides a lightweight and efficient alternative to platforms like GitHub. It’s designed to be easy to install and manage, making it an ideal choice for developers and teams looking to maintain control over their code repositories. This guide will walk you through the process of installing Gogs on Rocky Linux 9, ensuring you have all the necessary steps, troubleshooting tips, and resources to get started smoothly.
Prerequisites
Before diving into the installation process, ensure you meet the following prerequisites:
- System Requirements: A server running Rocky Linux 9 with at least 1GB of RAM and 1 CPU core.
- User Permissions: You need root or sudo privileges to install packages and configure services.
- Supported Databases: Gogs supports several databases, including SQLite3, PostgreSQL, MySQL, and MariaDB. Ensure you have one of these databases installed.
- Network Configuration: Ensure your server is accessible over the network and that you can reach it via SSH.
Step 1: Checking for System Upgrades
It’s essential to start with an updated system. Run the following command to check for any pending updates:
sudo dnf update -y
This command updates all installed packages to their latest versions, ensuring compatibility and security.
Step 2: Installing Required Packages
Gogs requires certain packages to function correctly. Install Git and other necessary utilities using the following command:
sudo dnf install git wget unzip -y
This command installs Git for version control, wget for downloading files, and unzip for extracting compressed files.
Step 3: Creating a Git User
For security purposes, it’s best practice to run Gogs under a dedicated user account. Create a new user named “git” with the following commands:
sudo useradd -m -s /bin/bash git
sudo passwd git
This creates a new user with a home directory and sets a password for it.
Step 4: Downloading Gogs
Next, download the latest version of Gogs from its official GitHub repository. Use the following command:
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 -
This command fetches the latest release URL and downloads it directly to your server. After downloading, extract the files:
unzip gogs_*_linux_amd64.zip
Step 5: Configuring Gogs
After extraction, move the Gogs binary to a suitable location. For example:
sudo mv gogs /home/git/gogs
Change ownership of the directory to the “git” user:
sudo chown -R git:git /home/git/gogs
Create Log Directory
Create a directory for logs to help manage log files generated by Gogs:
sudo mkdir /var/log/gogs
sudo chown -R git:git /var/log/gogs
Step 6: Configuring the Database
You need to set up a database for Gogs. Here’s how to create a database using MySQL (similar steps apply for PostgreSQL or SQLite):
Create Database in MySQL
# Log into MySQL
mysql -u root -p
# Create database
CREATE DATABASE gogs;
# Create user
CREATE USER 'gogs'@'localhost' IDENTIFIED BY 'your_password';
# Grant privileges
GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost';
# Flush privileges
FLUSH PRIVILEGES;
# Exit
EXIT;
Edit Configuration File
Edit the configuration file located in the Gogs directory:
nano /home/git/gogs/custom/conf/app.ini
You’ll need to set the database type and connection details in this file. For example:
[database]
DB_TYPE = mysql
HOST = localhost:3306
NAME = gogs
USER = gogs
PASSWD = your_password
SSL_MODE = disable
Step 7: Running Gogs as a Service
You can run Gogs as a service using systemd. First, create a systemd service file:
[Unit]
Description=Gogs Git Service
After=network.target
[Service]
User=git
Group=git
WorkingDirectory=/home/git/gogs
ExecStart=/home/git/gogs/gogs web
Restart=always
[Install]
WantedBy=multi-user.target
Create this file at `/etc/systemd/system/gogs.service
`:
sudo nano /etc/systemd/system/gogs.service
Enable and Start Gogs Service
Reload systemd to recognize the new service file and start Gogs:
sudo systemctl daemon-reload
sudo systemctl start gogs
sudo systemctl enable gogs
Status Check
You can check if Gogs is running properly with this command:
sudo systemctl status gogs
Step 8: Configuring Firewall Rules
If your server has a firewall enabled, ensure that you allow traffic on the port that Gogs uses (default is port 3000). Use these commands to configure your firewall:
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload
Step 9: Accessing Gogs Web Interface
You can access Gogs by navigating to your server’s IP address followed by port 3000 in your web browser:
http://your_server_ip:3000/install
Create Admin Account
The first time you access Gogs, you’ll be prompted to create an admin account. Fill in your details and configure any additional settings as needed.
Troubleshooting Tips
- If you encounter issues starting Gogs, check logs in `
/var/log/gogs
` for detailed error messages. - If you can’t access the web interface, ensure that your firewall settings allow traffic on port 3000.
- If database connection issues arise, verify that your database credentials are correct in `
app.ini
`. - If you receive permission errors, ensure that all files in `
/home/git/gog
s` are owned by the “git
” user.
Congratulations! You have successfully installed Gogs. Thanks for using this tutorial for installing the Gogs on Rocky Linux 9 system. For additional help or useful information, we recommend you check the official Gogs website.