Steps to Install & Configure Gogs on Ubuntu 20.04 LTS

In this post we are going to discuss about for Gogs Git service on Ubuntu. Gogs is an open source Git service written in Go language. Gogs web interface  is very similar to GitHub and offers support for MySQL, PostgreSQL, and SQLite database. Using Gogs web interface ,we can create, manage the repositorys.

There are some steps to setup Gogs Service on Ubuntu:

Step 1: Update the System.

apt-get update

Step 2: Install MySQL on system.

apt install mysql-server

  • Start & Enable the MySQL.

systemctl start mysql
systemctl enable mysql

  • Here is the command output.

[email protected]:/home/ubuntu# systemctl start mysql
[email protected]:/home/ubuntu# systemctl enable mysql
Synchronizing state of mysql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mysql

Step 3: Login to MySQL console.

mysql -u root -p

  • Press Enter.
  • Here is the command output.

[email protected]:/home/ubuntu# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  • To Set the global variables.

SET GLOBAL innodb_file_per_table = ON;

  • Create Database.

CREATE DATABASE gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

  • Create User & Set the Password.

CREATE USER 'gogs_user'@'localhost' IDENTIFIED BY 'Password';

  • Provide Grant All privileges on database to db user.

GRANT ALL PRIVILEGES ON gogs.* TO 'gogs_user'@'localhost';

  • Flush privileges & Exit from the MySQL console.

flush privileges;

  • Here is the command output.

mysql> SET GLOBAL innodb_file_per_table = ON;
Query OK, 0 rows affected (0.00 sec
mysql> CREATE DATABASE gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
Query OK, 1 row affected (0.01 sec)
mysql> CREATE USER 'gogs_user'@'localhost' IDENTIFIED BY 'Password';
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL PRIVILEGES ON gogs.* TO 'gogs_user'@'localhost';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> exit;

Step 4: Download the Gogs.

  • Install the required packages.

apt install wget curl vim

  • Run the following command to download the Gogs.

curl -s | grep browser_download_url | grep '\linux_amd64.tar.gz' | cut -d '"' -f 4 | wget -i -

  • Here is the command output.

[email protected]:/home/ubuntu# curl -s | grep browser_download_url | grep '\linux_amd64.tar.gz' | cut -d '"' -f 4 | wget -i -
--2022-01-26 08:10:05--
Resolving (
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 302 Found
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 26666184 (25M) [application/octet-stream]
Saving to: ‘gogs_0.12.4_linux_amd64.tar.gz’
gogs_0.12.4_linux_amd64.tar.gz 100%[===========================================================================================>] 25.43M 11.8MB/s in 2.2s
2022-01-26 08:10:08 (11.8 MB/s) - ‘gogs_0.12.4_linux_amd64.tar.gz’ saved [26666184/26666184]
FINISHED --2022-01-26 08:10:08--
Total wall clock time: 3.9s
Downloaded: 1 files, 25M in 2.2s (11.8 MB/s)

  • Extract the downloaded folder.

tar xvf gogs_*_linux_amd64.tar.gz

  • Here is the command output.

[email protected]:/home/ubuntu# tar xvf gogs_*_linux_amd64.tar.gz

Step 5: Now,Configure the Gogs self-hosted Git service.

  • Create a user to run Gogs service.

adduser git

  • Provide the password.
  • Leave the other options & Type Y.
  • Here is the command output.

[email protected]:/home/ubuntu# 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' ...
New password:
Retype new 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 the Logs directory & Provide the permission on it.

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

  • Copy the gogs systemd service file to /etc/systemd/system directory.

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

  • Open the Gogs systemd service file.

vim /etc/systemd/system/gogs.service

  • Edit the following line.

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

  • Move the gogs to /home/git & change the ownership of /home/git/to user(git).

mv gogs /home/git/
chown -R git:git /home/git/

  • Reload systemd,Start & Enable gogs service.

systemctl daemon-reload
systemctl start gogs
systemctl enable gogs

  • Check the Gogs service status.

systemctl status gogs

  • Here is the command output.

[email protected]:/home/ubuntu# systemctl status gogs
● gogs.service - Gogs
Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-01-26 08:16:50 UTC; 33min ago
Main PID: 3709 (gogs)
Tasks: 7 (limit: 4693)
Memory: 47.3M
CGroup: /system.slice/gogs.service
└─3709 /home/git/gogs/gogs web -port 3000

  • Type /home/git/gogs/gogs on terminal to open help page.


  • Here is the command output.

[email protected]:/home/ubuntu# /home/git/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 6: Now Install Gogs using Web interface.


  • Here is the output.

  • In Database Settings,Select the database type:-MySQL.
  • Provide the db user-name,password & database-name.

  • In Application Settings,Provide the application name.
  • In domain option,provide the Server-IP address.
  • Change the application URL (http://server-ip:3000).

  • In Optional Settings,Click on Email Settings.

  • Provide the required information such as SMTP Host,from,sender Email & sender password.
  • Enable the Email Notifications otherwise leave the email service settings.

  • Next is,Server & Other Services  Settings.
  • By default,Captcha is Enabled.


  • In Admin Account Settings,
  • Provide the username,password & Admin Email address.
  • Click on Install Gogs.

  • Now Gogs is Ready.

  • Add or create a Repository.
  • Click on My Repository + (plus) Option.

  • Provide the Repository name.
  • Leave the other options.
  • Click on Create Repository.

  • Repository has been created.
  • Copy the HTTP Clone URL.

  • Now Clone this repository from the system terminal.


git clone http://server-ip:3000/username/repo-name


git clone

  • Here is the command output.
  • Provide the Gogs username & Password.

[email protected]:/home/ubuntu# git clone
Cloning into 'test-repo'...
Username for '': Administrator
Password for 'http://[email protected]:3000':
warning: You appear to have cloned an empty repository.

Leave a Reply