How To Install Gogs Git service on Ubuntu 20.04|18.04

Posted on 89 views

This tutorial will cover all the steps required to Install Gogs self-hosted Git service on Ubuntu 20.04|18.04|16.04 server. Gogs project which is written in Go aims to build a simple, stable and extensible self-hosted Git service with a painless setup process. Gogs is distributed as an independent binary distribution and runs on all platforms that Go supports, including Linux, macOS, Windows, and ARM.

Gogs has excellent performance and is very light. It has very minimal RAM and CPU utilization. A VPS with 1 CPU core and 256MB RAM is enough to start using the service.

Features of Gogs

Gogs self-hosted Git service has the following set of features ( from Git )

  • Activity timeline
  • SMTP/LDAP/Reverse proxy authentication
  • Account/Organization/Repository management
  • Repository Git hooks/deploy keys
  • SSH and HTTP/HTTPS protocols
  • Reverse proxy with sub-path
  • Add/Remove repository collaborators
  • Web editor for repository files and wiki
  • Migrate and mirror repository and its wiki
  • Repository/Organization webhooks (including Slack and Discord)
  • Repository issues pull requests, wiki, and protected branches
  • Two-factor authentication
  • Gravatar and Federated avatar with custom source
  • Jupyter Notebook
  • Administration panel
  • Mail service
  • Supports MySQL, PostgreSQL, SQLite3, MSSQL and TiDB (via MySQL protocol)
  • Multi-language support (29 languages)

Gogs Open Source Components

Gogs components include:

Install Gogs Git service on Ubuntu 20.04|18.04

Follow these steps to have Gogs installed on your Ubuntu server.

Step 1: Install MariaDB Database Server

Gogs requires a MySQL server to store data. We will install MariaDB server using the following commands:

sudo apt update
sudo apt install mariadb-server mariadb

Once the database server has been installed, login to MariaDB console as root user

$ mysql -u root -p

Set global variables below

SET GLOBAL innodb_file_per_table = ON;

Then create gogs database


Create a dedicated database user to manage gogs database.

$ mysql -u root -p
GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost' IDENTIFIED BY "StrongPassword";

Step 2: Download Gogs from Github

Check Gogs releases page for the latest release.

sudo apt install wget curl vim -y
curl -s | grep browser_download_url | grep '\linux_amd64.tar.gz' | cut -d '"' -f 4 | wget -i -

Extract the downloaded file

tar xvf gogs_*_linux_amd64.tar.gz

Step 3: Configure Gogs self-hosted Git service

Create git user to run gogs service

$ sudo adduser git
Adding user `git' ...
Adding new group `git' (1001) ...
Adding new user `git' (1001) with group `git' ...
Creating home directory `/home/git' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for git
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] y

Create logs directory

sudo mkdir /var/log/gogs
sudo chown -R git:git /var/log/gogs/

Copy gogs systemd service file to /etc/systemd/system directory

sudo cp gogs/scripts/systemd/gogs.service /etc/systemd/system

You can edit the file to set customize the settings:

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

If you have a different service using port,3000 you can set a custom port

ExecStart=/home/git/gogs web -port 3001

Move the gogs directory content inside /home/git

sudo mv gogs /home/git/

Change ownership of /home/git/to user.git

sudo chown -R git:git /home/git/

Reload systemd and start gogs service

sudo systemctl daemon-reload
sudo systemctl start gogs

Enable the service to start on boot

sudo systemctl enable gogs

You can check service status by running

$ systemctl status gogs
● gogs.service - Gogs
     Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-10-26 23:12:31 UTC; 13s ago
   Main PID: 3404 (gogs)
      Tasks: 8 (limit: 2343)
     Memory: 41.4M
     CGroup: /system.slice/gogs.service
             └─3404 /home/git/gogs/gogs web

Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Log mode: Console (Trace)
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [ INFO] Gogs 0.12.3
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Work directory: /home/git/gogs
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Custom path: /home/git/gogs/custom
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Custom config: /home/git/gogs/custom/conf/app.ini
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Log path: /home/git/gogs/log
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Build time: 2020-10-07 03:03:48 UTC
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Build commit: f0e3cd90f8d7695960eeef2e4e54b2e717302f6c
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [ INFO] Run mode: Development
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [ INFO] Listen on

Typing command gogs on the terminal as git user should print help page.

$ gogs/gogs
   Gogs - A painless self-hosted Git service

   gogs [global options] command [command options] [arguments...]


   web      Start web server
   serv     This command should only be called by SSH shell
   hook     Delegate commands to corresponding Git hooks
   cert     Generate self-signed certificate
   admin    Perform admin operations on command line
   import   Import portable data as local Gogs data
   backup   Backup files and database
   restore  Restore files and database from backup
   help, h  Shows a list of commands or help for one command

   --help, -h     show help
   --version, -v  print the version

Step 4: Configure Gogs self-hosted Git service

Open the URL http://serverip:3000/install to finish the installation of Gogs

Set database authentication


The username and password provided should match the ones provided in the Database configuration section. If the database server is on a different host, provide the IP address under the Host section.

Set Application General Settings

Provide application URL, this can be a routable server IP address or domain name that resolves to the IP. The same should be set for SSH.


Disable User self-registration

You can disable User self-registration under “Server and Other Services Settings”. This means the admin user will manually create user accounts.


You can optionally create an admin user account. By default, root user will gain admin access automatically.


When done with the configurations, click the “Install Gogs” button to finish the installation. On a successful installation, you should be logged into Gogs administration console.

Create additional user accounts

To add user accounts, Open Admin Panel at the top right panel


You can then use “Create New Account” link to add a new user to Gogs.


Step: 5 Test Gogs self-hosted Git service

Create a new repository called test-repo

Try cloning the repo

$ git clone
Cloning into 'test-repo'...
Username for '': jmutai
Password for 'http://[email protected]:3000': 
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done

To avoid Password Authentication, add your SSH public key under “Your Profile > SSH keys > Add Key


Provide key name, and paste your SSH public key into the content box.


An ssh git clone should not ask for a password

$ git clone [email protected]:jmutai/test-repo.git
Cloning into 'test-repo'...
Warning: Permanently added '' (ECDSA) to the list of known hosts.
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (4/4), done.

Step 6: Configure Nginx Reverse Proxy

If you would like to access Gogs using a domain name without a port, you need to configure Apache or NGINX reverse proxy

sudo apt install nginx

Create a VirtualHost reverse proxy configuration file

sudo vim /etc/nginx/conf.d/gogs.conf


    listen 80;

    location / 
        proxy_pass http://localhost:3000;

If using SSL and would like to have http to https redirect, use:

	listen 80;
	location / 
        	rewrite     ^$request_uri? permanent;

        listen       443 ssl;
	ssl_certificate /etc/letsencrypt/live/;
	ssl_certificate_key /etc/letsencrypt/live/;

        location / 
            proxy_pass http://localhost:3000;

Replace with your actual domain name. For more reading on Gogs administration and usage, check out the Official Documentation.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.