Operating System Debian

Set Up Gogs on Debian 13 or Ubuntu 26.04 With PostgreSQL and Nginx

Install Gogs from the official release binary on Debian 13 or Ubuntu 26.04, backed by PostgreSQL, run by systemd and published through Nginx.

Gogs is a lightweight self-hosted Git service written in Go. This guide installs the official pre-built binary on Debian 13 or Ubuntu 26.04 LTS (the commands are identical, and also work on Debian 12 and Ubuntu 24.04), stores its data in PostgreSQL, runs it as a systemd service and publishes it through Nginx. At the end you can use the web interface at http://git.example.com and clone or push over HTTP and SSH.

Gogs is actively maintained; the examples use version 0.14.4, released in November 2026. Check the releases page for the current version before you download, because recent releases consist largely of security fixes.

Requirements

  • A server with Debian 13 or Ubuntu 26.04 and a non-root user with sudo rights.
  • A DNS name pointing to the server, here git.example.com.
  • Git and, for SSH access, the OpenSSH server that is already running on a typical VPS.

Install the packages

sudo apt update
sudo apt install -y git postgresql nginx curl

Create the database

Create a PostgreSQL role and a UTF-8 database owned by it. Replace the password with your own and note it for the installer.

sudo -u postgres psql -c "CREATE USER gogs WITH PASSWORD 'change-this-password';"
sudo -u postgres psql -c "CREATE DATABASE gogs OWNER gogs ENCODING 'UTF8';"

Gogs also supports MySQL, MariaDB and SQLite 3 if you prefer one of those.

Create the git user and download Gogs

Gogs runs as an unprivileged user, conventionally called git. The same account is used for SSH access to repositories, which is why clone URLs look like git@git.example.com:user/repo.git.

sudo adduser --disabled-password --gecos "Gogs" git

Download and unpack the release for your architecture into the user's home directory. For 64-bit x86 servers:

GOGS_VERSION=0.14.4
curl -fL -o /tmp/gogs.tar.gz https://github.com/gogs/gogs/releases/download/v${GOGS_VERSION}/gogs_v${GOGS_VERSION}_linux_amd64.tar.gz
sudo -u git tar -xzf /tmp/gogs.tar.gz -C /home/git/
rm /tmp/gogs.tar.gz

On ARM servers replace amd64 with arm64. The archive unpacks to /home/git/gogs, which contains the gogs binary and a scripts directory.

Run Gogs as a systemd service

The archive includes a unit file that already matches this layout (user git, working directory /home/git/gogs). Install and start it:

sudo cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now gogs
sudo systemctl status gogs

Gogs now listens on port 3000. Until the next sections are done it answers on every interface, so do not open port 3000 in your firewall.

Configure Nginx as a reverse proxy

Create a site that forwards requests to Gogs:

sudo nano /etc/nginx/sites-available/gogs
server {
    listen 80;
    listen [::]:80;
    server_name git.example.com;

    client_max_body_size 100m;

    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;
    }
}

client_max_body_size controls how large a push over HTTP may be; raise it if your repositories need it. Enable the site and reload Nginx:

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

For production use, add a TLS certificate to this server block (for example with Certbot) and use https:// in the application URL below.

Run the first-time installer

Open http://git.example.com in your browser. Gogs 0.14 shows its installation page on the first run. Fill in:

  • Database type: PostgreSQL
  • Host: 127.0.0.1:5432
  • User / Database name: gogs / gogs
  • Password: the database password you chose
  • Run user: git
  • Domain: git.example.com
  • Application URL: http://git.example.com/

Create the administrator account in the same form; otherwise the first user who registers becomes the administrator. Click Install Gogs. The settings are written to /home/git/gogs/custom/conf/app.ini.

Restrict Gogs to localhost

With Nginx in front, Gogs itself should only accept local connections. Edit the configuration file:

sudo -u git nano /home/git/gogs/custom/conf/app.ini

In the [server] section add or change:

HTTP_ADDR = 127.0.0.1

If you do not want strangers to create accounts, also set this in the [auth] section:

DISABLE_REGISTRATION = true

Restart the service to apply the changes:

sudo systemctl restart gogs

Verify

Sign in, add your SSH public key under your account settings, create a repository and clone it both ways:

git clone http://git.example.com/youruser/test.git
git clone git@git.example.com:youruser/test.git

If something fails, look at sudo journalctl -u gogs and the files in /home/git/gogs/log.

Back up and upgrade

Gogs has a built-in backup command that writes the database, repositories and related files into one zip archive. Run it as the git user from the installation directory:

cd /home/git/gogs
sudo -u git ./gogs backup --target /home/git

To upgrade, read the release notes, stop the service, take a backup, unpack the new release over the installation directory and start the service again. Your settings, data and logs live in custom, data and log and are not part of the archive.

sudo systemctl stop gogs
curl -fL -o /tmp/gogs.tar.gz https://github.com/gogs/gogs/releases/download/v${GOGS_VERSION}/gogs_v${GOGS_VERSION}_linux_amd64.tar.gz
sudo -u git tar -xzf /tmp/gogs.tar.gz -C /home/git/
sudo systemctl start gogs

Set GOGS_VERSION to the new version first. The project's changelog announces that the release after 0.14 removes the web installer, requires Git 2.43.1 or later and PostgreSQL 12 or later, and disables self-registration by default, so read the notes before moving to it. Details are in the Gogs documentation.

Frequently asked questions

Can Gogs run its own SSH server instead of using the system one?

Yes. Setting START_SSH_SERVER = true in the [server] section starts a built-in SSH server on the port given by SSH_LISTEN_PORT. That is useful when you do not want Git access to go through the system's OpenSSH and its git account.

Where are the repositories stored?

In the repository root path shown on the installation page, by default a gogs-repositories directory in the home directory of the run user. Include it in your backups; gogs backup does so unless you exclude repositories.

How do I create an administrator from the command line?

Run sudo -u git ./gogs admin create-user --name admin --password 'secret' --email admin@example.com --admin --config custom/conf/app.ini from /home/git/gogs. The command talks to the database directly, so it must run on the server.

How does Gogs relate to Gitea and Forgejo?

Gitea started as a fork of Gogs in 2016 and Forgejo later forked from Gitea. Both have grown more features, such as built-in CI. Gogs stays deliberately small and is a good fit when you want plain Git hosting with low resource use.

Share story:

Continue reading other guides on How VPS.