Gogs (Go Git Service) is a lightweight, self-hosted Git platform that allows developers to host repositories, manage projects, and collaborate efficiently. Setting up Gogs on Ubuntu 24.04 provides you with a private, customizable Git server that is easy to install and maintain. Whether you’re a developer, team lead, or hobbyist, installing Gogs helps streamline your version control workflows without relying on third-party hosting services. Before starting, ensure you have a clean Ubuntu 24.04 server or VM with a fresh installation, and that you have root or sudo privileges.
What You’ll Need
- Ubuntu 24.04 server or desktop environment with sudo privileges
- Basic knowledge of Linux command line
- Internet connection to download packages and Gogs binaries
- Domain name (optional but recommended for production use)
- Firewall access to open necessary ports (default 3000 for web UI, 22 for SSH)
Step-by-Step
- Update your system packages
sudo apt update && sudo apt upgrade -yThis ensures your system has the latest security patches and package versions.
- Install dependencies
sudo apt install -y git mariadb-server nginx certbot ufwYou need Git for cloning repositories, MariaDB as the database backend, Nginx as a reverse proxy, Certbot for SSL, and UFW for firewall configuration.
- Create a dedicated user for Gogs
sudo adduser --system --group --disabled-login gogsThis user will run the Gogs service securely.
- Download the latest Gogs binary
wget -O /tmp/gogs.tar.gz https://github.com/gogs/gogs/releases/latest/download/gogs_0.12.3_linux_amd64.tar.gzReplace the URL with the latest release URL from Gogs GitHub releases if needed.
- Extract and install Gogs
sudo tar -xzf /tmp/gogs.tar.gz -C /opt/ sudo mv /opt/gogs /opt/gogsSet proper permissions:
sudo chown -R gogs:gogs /opt/gogs - Configure Gogs
Create a configuration directory:sudo mkdir -p /etc/gogsCopy the sample config:
sudo cp /opt/gogs/custom/conf/app.ini /etc/gogs/Set ownership:
sudo chown -R gogs:gogs /etc/gogsEdit the configuration:
sudo nano /etc/gogs/app.iniIn the file, set database connection details (e.g., database type, host, user, password), server URL, and other preferences. For example, configure the [database] section to connect to MariaDB.
- Set up the database
Login to MariaDB:sudo mysql -u root -pCreate a database and user:
CREATE DATABASE gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'gogsuser'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON gogs.* TO 'gogsuser'@'localhost'; FLUSH PRIVILEGES; EXIT;Update your app.ini with these database credentials.
- Set up systemd service for Gogs
Create a service file:sudo nano /etc/systemd/system/gogs.servicePaste the following content:
[Unit] Description=Gogs After=network.target [Service] User=gogs Group=gogs WorkingDirectory=/opt/gogs ExecStart=/opt/gogs/gogs web Restart=always Environment=USER=gogs [Install] WantedBy=multi-user.targetEnable and start the service:
sudo systemctl daemon-reload sudo systemctl enable gogs sudo systemctl start gogs - Configure Nginx as a reverse proxy
Create an Nginx server block:sudo nano /etc/nginx/sites-available/gogsInsert configuration:
server { listen 80; server_name your.domain.com; location / { proxy_pass http://127.0.0.1:3000; 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; } }Enable the site:
sudo ln -s /etc/nginx/sites-available/gogs /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx - Secure Gogs with SSL
Use Certbot to obtain a free SSL certificate:sudo certbot --nginx -d your.domain.comFollow prompts to configure SSL automatically. Afterward, ensure your Gogs URL in app.ini uses https.
- Access your Gogs instance
Open your browser and navigate to http://your.domain.com or https://your.domain.com if SSL is configured. You should see the Gogs login page. Complete the initial setup by creating an admin account and configuring repositories.
Common Mistakes
- Not updating system packages before installation, leading to compatibility issues.
- Failing to set correct permissions on Gogs directories, causing service startup failures.
- Using an outdated or incorrect URL for the Gogs binary download, resulting in installation errors.
- Forgetting to restart or reload systemd and Nginx after configuration changes.
- Misconfiguring database credentials, which prevents Gogs from connecting to the database.
- Not opening the necessary firewall ports, making the web interface inaccessible externally.
Tips
- Always back up your database and configuration files before major changes.
- Use a domain name with SSL for production environments to secure your data.
- Regularly update Gogs and system packages to benefit from security patches and new features.
- Configure automatic backups for your repositories and database.
- Monitor Gogs logs located in /opt/gogs/log for troubleshooting.
Troubleshooting
If Gogs does not start properly or you encounter errors:
- Check the status of the Gogs systemd service:
sudo systemctl status gogsLook for error messages related to permissions or missing dependencies.
- Review Gogs logs in /opt/gogs/log/ for detailed error information.
- Ensure the database is reachable and credentials are correct in app.ini.
- Verify that the firewall allows traffic on ports 80, 443, and 3000 if used.
- Test network connectivity to your server and domain name.
- If SSL certificates fail, re-run Certbot or check your DNS settings.
Following these steps and tips should help you successfully install and run Gogs on Ubuntu 24.04, providing a robust, self-hosted Git platform tailored to your needs.
Related
- How to Clear Cache on iPhone 15 for Better Performance
- How to Clear Cache on iPhone 13 for Better Performance
- How to Clear Cache on iPhone 12 for Better Performance