gogs is a free and open-source self-hosted Git service. Gogs provides a painless self-hosted Git service written in Go
1. Prerequisites
2. Supported Operating Systems
This guide supports installation on:
3. Installation
RHEL/CentOS/Rocky Linux/AlmaLinux
# Install EPEL repository if needed
sudo dnf install -y epel-release
# Install gogs
sudo dnf install -y gogs
# Enable and start service
sudo systemctl enable --now gogs
# Configure firewall
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload
# Verify installation
gogs --version
Debian/Ubuntu
# Update package index
sudo apt update
# Install gogs
sudo apt install -y gogs
# Enable and start service
sudo systemctl enable --now gogs
# Configure firewall
sudo ufw allow 3000
# Verify installation
gogs --version
Arch Linux
# Install gogs
sudo pacman -S gogs
# Enable and start service
sudo systemctl enable --now gogs
# Verify installation
gogs --version
Alpine Linux
# Install gogs
apk add --no-cache gogs
# Enable and start service
rc-update add gogs default
rc-service gogs start
# Verify installation
gogs --version
openSUSE/SLES
# Install gogs
sudo zypper install -y gogs
# Enable and start service
sudo systemctl enable --now gogs
# Configure firewall
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload
# Verify installation
gogs --version
macOS
# Using Homebrew
brew install gogs
# Start service
brew services start gogs
# Verify installation
gogs --version
FreeBSD
# Using pkg
pkg install gogs
# Enable in rc.conf
echo 'gogs_enable="YES"' >> /etc/rc.conf
# Start service
service gogs start
# Verify installation
gogs --version
Windows
# Using Chocolatey
choco install gogs
# Or using Scoop
scoop install gogs
# Verify installation
gogs --version
Initial Configuration
Basic Configuration
# Create configuration directory
sudo mkdir -p /etc/gogs
# Set up basic configuration
# See official documentation for detailed configuration options
# Test configuration
gogs --version
5. Service Management
systemd (RHEL, Debian, Ubuntu, Arch, openSUSE)
# Enable service
sudo systemctl enable gogs
# Start service
sudo systemctl start gogs
# Stop service
sudo systemctl stop gogs
# Restart service
sudo systemctl restart gogs
# Check status
sudo systemctl status gogs
# View logs
sudo journalctl -u gogs -f
OpenRC (Alpine Linux)
# Enable service
rc-update add gogs default
# Start service
rc-service gogs start
# Stop service
rc-service gogs stop
# Restart service
rc-service gogs restart
# Check status
rc-service gogs status
rc.d (FreeBSD)
# Enable in /etc/rc.conf
echo 'gogs_enable="YES"' >> /etc/rc.conf
# Start service
service gogs start
# Stop service
service gogs stop
# Restart service
service gogs restart
# Check status
service gogs status
launchd (macOS)
# Using Homebrew services
brew services start gogs
brew services stop gogs
brew services restart gogs
# Check status
brew services list | grep gogs
Windows Service Manager
# Start service
net start gogs
# Stop service
net stop gogs
# Using PowerShell
Start-Service gogs
Stop-Service gogs
Restart-Service gogs
# Check status
Get-Service gogs
Advanced Configuration
See the official documentation for advanced configuration options.
Reverse Proxy Setup
nginx Configuration
upstream gogs_backend {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name gogs.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name gogs.example.com;
ssl_certificate /etc/ssl/certs/gogs.example.com.crt;
ssl_certificate_key /etc/ssl/private/gogs.example.com.key;
location / {
proxy_pass http://gogs_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Apache Configuration
<VirtualHost *:80>
ServerName gogs.example.com
Redirect permanent / https://gogs.example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName gogs.example.com
SSLEngine on
SSLCertificateFile /etc/ssl/certs/gogs.example.com.crt
SSLCertificateKeyFile /etc/ssl/private/gogs.example.com.key
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
</VirtualHost>
HAProxy Configuration
frontend gogs_frontend
bind *:80
bind *:443 ssl crt /etc/ssl/certs/gogs.pem
redirect scheme https if !{ ssl_fc }
default_backend gogs_backend
backend gogs_backend
balance roundrobin
server gogs1 127.0.0.1:3000 check
Security Configuration
Basic Security Setup
# Set appropriate permissions
sudo chown -R gogs:gogs /etc/gogs
sudo chmod 750 /etc/gogs
# Configure firewall
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload
# Enable SELinux policies (if applicable)
sudo setsebool -P httpd_can_network_connect on
Database Setup
See official documentation for database configuration requirements.
Performance Optimization
System Tuning
# Basic system tuning
echo 'net.core.somaxconn = 65535' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_max_syn_backlog = 65535' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Monitoring
Basic Monitoring
# Check service status
sudo systemctl status gogs
# View logs
sudo journalctl -u gogs -f
# Monitor resource usage
top -p $(pgrep gogs)
9. Backup and Restore
Backup Script
#!/bin/bash
# Basic backup script
BACKUP_DIR="/backup/gogs"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p "$BACKUP_DIR"
tar -czf "$BACKUP_DIR/gogs-backup-$DATE.tar.gz" /etc/gogs /var/lib/gogs
echo "Backup completed: $BACKUP_DIR/gogs-backup-$DATE.tar.gz"
Restore Procedure
# Stop service
sudo systemctl stop gogs
# Restore from backup
tar -xzf /backup/gogs/gogs-backup-*.tar.gz -C /
# Start service
sudo systemctl start gogs
6. Troubleshooting
Common Issues
1. Service won't start:
# Check logs
sudo journalctl -u gogs -n 100
sudo tail -f /var/log/gogs/gogs.log
# Check configuration
gogs --version
# Check permissions
ls -la /etc/gogs
2. Connection issues:
# Check if service is listening
sudo ss -tlnp | grep 3000
# Test connectivity
telnet localhost 3000
# Check firewall
sudo firewall-cmd --list-all
3. Performance issues:
# Check resource usage
top -p $(pgrep gogs)
# Check disk I/O
iotop -p $(pgrep gogs)
# Check connections
ss -an | grep 3000
Integration Examples
Docker Compose Example
version: '3.8'
services:
gogs:
image: gogs:latest
ports:
- "3000:3000"
volumes:
- ./config:/etc/gogs
- ./data:/var/lib/gogs
restart: unless-stopped
Maintenance
Update Procedures
# RHEL/CentOS/Rocky/AlmaLinux
sudo dnf update gogs
# Debian/Ubuntu
sudo apt update && sudo apt upgrade gogs
# Arch Linux
sudo pacman -Syu gogs
# Alpine Linux
apk update && apk upgrade gogs
# openSUSE
sudo zypper update gogs
# FreeBSD
pkg update && pkg upgrade gogs
# Always backup before updates
tar -czf /backup/gogs-pre-update-$(date +%Y%m%d).tar.gz /etc/gogs
# Restart after updates
sudo systemctl restart gogs
Regular Maintenance
# Log rotation
sudo logrotate -f /etc/logrotate.d/gogs
# Clean old logs
find /var/log/gogs -name "*.log" -mtime +30 -delete
# Check disk usage
du -sh /var/lib/gogs
Additional Resources
---
Note: This guide is part of the HowToMgr collection. Always refer to official documentation for the most up-to-date information.