Setting Up Gogs on Ubuntu 24.04 Server

By Raman Kumar

Updated on Jul 03, 2025

Set up Gogs with MySQL on Ubuntu 24.04 to host a lightweight Git server for our development team. This guide shows how to install and configure everything securely and efficiently, helping us take full control of our code without relying on GitHub or GitLab.

What is Gogs?

Gogs, short for Go Git Service, is an open-source, self-hosted Git server written entirely in Go. It’s designed to be extremely lightweight, fast, and simple to deploy on virtually any platform — whether that’s Linux, macOS, Windows, or even ARM-based devices like Raspberry Pi.

What makes Gogs stand out is its minimal resource usage and ease of installation. We don’t need to configure a heavy stack or worry about large system dependencies. It runs as a single binary with a built-in web UI, making it perfect for small teams, individual developers, or businesses that want full control over their code repositories without relying on platforms like GitHub or GitLab.

Gogs supports SSH/HTTPS, user authentication, repository management, pull requests, webhooks, issue tracking, and more—all packaged in a clean, fast, and user-friendly interface.

Prerequisites

Before we begin, let’s ensure our environment meets the following requirements:

  • A Ubuntu 24.04 installed dedicated server or KVM VPS.
  • A non-root user with sudo privileges.
  • Basic knowledge of using the terminal.
  • A domain name pointing to server IP.

Setting Up Gogs on Ubuntu 24.04 Server

Step 1: Update Our Server

Before we begin, make sure the system is fully updated.

sudo apt update && sudo apt upgrade -y

Step 2: Install MySQL Server

We’ll use MySQL as the backend database for Gogs.

sudo apt install mysql-server -y

Once installed, secure the setup:

sudo mysql_secure_installation

Follow the prompts to set the root password and remove anonymous users.

Step 3: Create a MySQL Database for Gogs

Log into the MySQL shell:

sudo mysql -u root -p

Then run:

CREATE DATABASE gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'gogsuser'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL PRIVILEGES ON gogs.* TO 'gogsuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace 'strong_password_here' with a secure password we’ll remember.

Step 4: Install Required Packages

sudo apt install git curl -y

Step 5: Create a System User for Gogs

sudo adduser --system --shell /bin/bash --gecos 'Gogs user' --group --disabled-password --home /home/gogs gogs

Step 6: Download and Extract Gogs

For latest version visit official Gogs download page .

cd /home/gogs
sudo -u gogs curl -L https://github.com/gogs/gogs/releases/download/v0.13.3/gogs_0.13.3_linux_amd64.tar.gz -o gogs.tar.gz
sudo -u gogs tar -xzf gogs.tar.gz

Now Gogs is ready to be started.

Step 7: Create a Systemd Service for Gogs

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

Paste the following:

[Unit]
Description=Gogs Git Service
After=network.target

[Service]
User=gogs
Group=gogs
WorkingDirectory=/home/gogs/gogs
ExecStart=/home/gogs/gogs/gogs web
Restart=always
Environment=USER=gogs HOME=/home/gogs

[Install]
WantedBy=multi-user.target

Now enable and start Gogs:

sudo systemctl daemon-reload
sudo systemctl enable --now gogs

Step 8: Configure Firewall (if UFW is enabled)

We need to open HTTP and HTTPS ports in firewall.

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

Step 9: Reverse Proxy with Nginx and HTTPS

Install Nginx:

sudo apt install nginx -y

Set up a basic config:

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

Add following content:

server {
    listen 80;
    server_name git.example.com;

    location / {
        proxy_pass http://localhost: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;
    }
}

Note: Replace git.example.com with your domain name.

Enable the site and reload:

sudo ln -s /etc/nginx/sites-available/gogs /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Add SSL using Certbot:

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d git.example.com

Step 10: Access the Gogs Web Interface

Open a browser and visit:

https://git.example.com

Now fill in the installation form:

  • Database Type: MySQL
  • Host: 127.0.0.1:3306
  • User: gogsuser
  • Password: the one we created earlier
  • Database Name: gogs

Other fields:

  • Application URL: https://git.example.com/
  • Repository Root Path: leave default
  • Run User: gogs
  • Domain: https://example.com/
  • Create an admin user at the bottom of the form

Click Install Gogs to complete the setup.

Final Thoughts

By setting up Gogs with MySQL on Ubuntu 24.04, we now have a secure, self-hosted Git server that’s lightweight, fast, and easy to manage. Whether we’re working solo or as a team, this gives us full control over our development workflow with no third-party lock-in.

Checkout our low cost dedicated servers.