Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

How to Install Gogs on Ubuntu 24.04 Easily and Quickly

How to Install Gogs on Ubuntu 24.04 Easily and Quickly

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

  1. Update your system packages
    sudo apt update && sudo apt upgrade -y

    This ensures your system has the latest security patches and package versions.

  2. Install dependencies
    sudo apt install -y git mariadb-server nginx certbot ufw

    You need Git for cloning repositories, MariaDB as the database backend, Nginx as a reverse proxy, Certbot for SSL, and UFW for firewall configuration.

  3. Create a dedicated user for Gogs
    sudo adduser --system --group --disabled-login gogs

    This user will run the Gogs service securely.

  4. 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.gz

    Replace the URL with the latest release URL from Gogs GitHub releases if needed.

  5. Extract and install Gogs
    sudo tar -xzf /tmp/gogs.tar.gz -C /opt/
    sudo mv /opt/gogs /opt/gogs

    Set proper permissions:

    sudo chown -R gogs:gogs /opt/gogs
  6. Configure Gogs
    Create a configuration directory:

    sudo mkdir -p /etc/gogs

    Copy the sample config:

    sudo cp /opt/gogs/custom/conf/app.ini /etc/gogs/

    Set ownership:

    sudo chown -R gogs:gogs /etc/gogs

    Edit the configuration:

    sudo nano /etc/gogs/app.ini

    In 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.

  7. Set up the database
    Login to MariaDB:

    sudo mysql -u root -p

    Create 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.

  8. Set up systemd service for Gogs
    Create a service file:

    sudo nano /etc/systemd/system/gogs.service

    Paste 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.target

    Enable and start the service:

    sudo systemctl daemon-reload
    sudo systemctl enable gogs
    sudo systemctl start gogs
  9. Configure Nginx as a reverse proxy
    Create an Nginx server block:

    sudo nano /etc/nginx/sites-available/gogs

    Insert 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
  10. Secure Gogs with SSL
    Use Certbot to obtain a free SSL certificate:

    sudo certbot --nginx -d your.domain.com

    Follow prompts to configure SSL automatically. Afterward, ensure your Gogs URL in app.ini uses https.

  11. 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:

  1. Check the status of the Gogs systemd service:
    sudo systemctl status gogs

    Look for error messages related to permissions or missing dependencies.

  2. Review Gogs logs in /opt/gogs/log/ for detailed error information.
  3. Ensure the database is reachable and credentials are correct in app.ini.
  4. Verify that the firewall allows traffic on ports 80, 443, and 3000 if used.
  5. Test network connectivity to your server and domain name.
  6. 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 Install Gogs on Ubuntu 24.04 Easily and Quickly
Scroll to top