This tutorial guides you through the process of hosting Gogs, a self-hosted Git service, on Rocky Linux 8. Gogs allows you to manage and collaborate on Git repositories with ease.
rocky linuxGogs
Large
VPS
3
vCPU
12 GB
Memory
120 GB
NVMe Disk
6144 GB
Traffic
29.90€
/month
* Up to 6 vCPU, 36GB RAM, 360GB NVMe Disk Space and 1Gbit/s Network Speed
#### Prerequisites
Before you begin, ensure you have:
- A server running Rocky Linux 8 (This guide is tested with Rocky Linux 8)
- A user account with sudo privileges
- Basic familiarity with the command line
#### Step 1: Install Required Dependencies
Ensure your system's package list is up-to-date, then install Git, MySQL (or MariaDB), and other necessary packages:
```bash
sudo dnf update
sudo dnf install git mariadb-server
```
Start and enable MariaDB to run on system boot:
```bash
sudo systemctl start mariadb
sudo systemctl enable mariadb
```
#### Step 2: Create a MySQL Database and User for Gogs
Log into MariaDB as the root user:
```bash
sudo mysql -u root -p
```
Create a new database and user for Gogs:
```sql
CREATE DATABASE gogs_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'gogs_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON gogs_db.* TO 'gogs_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
```
#### Step 3: Download and Install Gogs
Create a directory for Gogs and download the binary release from the official Gogs GitHub repository:
```bash
sudo mkdir -p /var/lib/gogs
sudo chmod 750 /var/lib/gogs
sudo chown -R your_user: /var/lib/gogs
wget --content-disposition https://github.com/gogs/gogs/releases/download/v0.12.3/gogs_0.12.3_Linux_amd64.tar.gz
tar -zxvf gogs_0.12.3_Linux_amd64.tar.gz
sudo mv gogs /var/lib/gogs/
```
#### Step 4: Configure Gogs
Navigate to the Gogs directory and run the Gogs web installer:
```bash
cd /var/lib/gogs/gogs
./gogs web
```
Follow the on-screen instructions to configure Gogs:
- Select MySQL (or MariaDB) as the database type.
- Enter the database connection details (`gogs_db`, `gogs_user`, password).
- Configure other settings such as server domain, SSH port, etc.
#### Step 5: Configure Nginx Reverse Proxy (Optional)
To access Gogs via a domain name and secure it with SSL, set up an Nginx reverse proxy. Create an Nginx server block configuration file:
```bash
sudo nano /etc/nginx/conf.d/gogs.conf
```
Add the following configuration (adjust domain and paths as necessary):
```nginx
server {
listen 80;
server_name git.yourdomain.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
}
}
```
Save and close the file. Test Nginx configuration:
```bash
sudo nginx -t
sudo systemctl restart nginx
```
#### Step 6: Access Gogs
Open your web browser and navigate to your server's domain name or IP address. You should see the Gogs login or registration page. Create an admin account and start using Gogs for managing Git repositories.
#### Conclusion
You have successfully set up Gogs Git service on Rocky Linux 8. Collaborate on code projects with your team using this self-hosted Git solution.
**Additional Resources:**
- **Gogs Documentation:** [https://gogs.io/docs](https://gogs.io/docs)
- **Rocky Linux Documentation:** [https://docs.rockylinux.org/](https://docs.rockylinux.org/)