Gogs is a free, open-source, simple, stable and extensible, self-hosted git service written in the Go programming language. It’s lightweight, cross-platform, and easy to install, so you can easily set up a self-hosted git service in your development environment. Gogs is distributed as an independent binary distribution and has minimal requirements so it can run on all platforms that Go supports, such as Windows, Linux, ARM, Mac, etc.

Features

  • Web-based administration panel
  • Supports SMTP/LDAP/Reverse proxy authentication
  • Provides web-based editor for repository files and wiki
  • Supports two-factor authentication
  • Supports MySQL, PostgreSQL, SQLite3 and MSSQL
  • Supports around 29 languages

In this tutorial, we will learn how to install Gogs on Ubuntu 18.04 server.

Requirements

  • A server running Ubuntu 18.04 LTS.
  • A static IP address is set up to your server.
  • A non-root user with sudo privileges.

Getting Started

Before starting, you will need to update your system with the latest version. You can do this by running the following command:

sudo apt-get update -y
sudo apt-get upgrade -y

Once your system is updated, restart the system to apply the changes.

Install and Configure MariaDB

First, you will need to install MariaDB server and other required packages to your system. You can install all of them with the following command:

sudo apt-get install mariadb-server git wget -y

Once all the packages are installed, you will need to change MariaDB default config file:

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

Add the following lines under [mysqld] section:

innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_default_row_format = dynamic

Save and close the file, when you are finished.

Next, log in to MariaDB shell with the following command:

mysql -u root -p

Enter your root password, then set global variables and create Gogs database with the following command:

MariaDB [(none)]> SET GLOBAL innodb_file_per_table = ON;
MariaDB [(none)]> CREAT DATABASE gogsdb;

Next, grant all the privileges on Gogs with the following command:

MariaDB [(none)]>GRANT ALL ON gogsdb.* TO 'gogs'@'localhost' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

Replace the word ‘mypassword’ with a secure password of your choice. Next, flush the privileges and exit from the MariaDB shell with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Next, start MariaDB service and enable it to start on boot time with the following command:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Download Gogs

First, you will need to install the latest version of the Gogs from Git repository. You can download it with the following command:

cd /tmp
wget https://github.com/gogs/gogs/releases/download/v0.11.66/linux_amd64.tar.gz

After downloading Gogs, extract the downloaded file with the following command:

tar -xvzf linux_amd64.tar.gz

Next, copy the extracted directory to /opt with the following command:

sudo cp -r gogs /opt/

Create Gogs System Service File

First, you will need to create a gogs user to run gogs service. You can do this with the following command:

sudo adduser gogs

Next, copy gogs systemd service file to /etc/systemd/system directory with the following command:

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

Next, edit gogs.service file and make some changes:

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

Make the following changes:

[Unit]
Description=Gogs
After=syslog.target
After=network.target
After=mariadb.service mysqld.service postgresql.service memcached.service redis.service

[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
Type=simple
User=gogs
Group=gogs
WorkingDirectory=/opt/gogs
ExecStart=/opt/gogs/gogs web
Restart=always
Environment=USER=gogs HOME=/opt/gogs

# Some distributions may not support these hardening directives. If you cannot start the service due
# to an unknown option, comment out the ones not supported by your version of systemd.
ProtectSystem=full
PrivateDevices=yes
PrivateTmp=yes
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

Save and close the file, when you are finished. Then, give proper permissions to the gogs directory with the following command:

sudo chown -R gogs:gogs /opt/gogs/
sudo chmod -R 777 /opt/gogs/

Next, start the gogs service and enable it to start on boot with the following command:

sudo systemctl start gogs
sudo systemctl enable gogs

You can now check the status of gogs service with the following command:

sudo systemctl status gogs

You should see the following output:

? gogs.service - Gogs
   Loaded: loaded (/etc/systemd/system/gogs.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-04-09 15:51:55 UTC; 4s ago
 Main PID: 6882 (gogs)
    Tasks: 7 (limit: 2323)
   CGroup: /system.slice/gogs.service
           ??6882 /opt/gogs/gogs web

Apr 09 15:51:55 ubuntu1804 gogs[6882]: 2019/04/09 15:51:55 [ WARN] Custom config '/opt/gogs/custom/conf/app.ini' not found, ignore this if you'
Apr 09 15:51:55 ubuntu1804 gogs[6882]: 2019/04/09 15:51:55 [TRACE] Custom path: /opt/gogs/custom
Apr 09 15:51:55 ubuntu1804 gogs[6882]: 2019/04/09 15:51:55 [TRACE] Log path: /opt/gogs/log
Apr 09 15:51:55 ubuntu1804 gogs[6882]: 2019/04/09 15:51:55 [TRACE] Log Mode: Console (Trace)
Apr 09 15:51:55 ubuntu1804 gogs[6882]: 2019/04/09 15:51:55 [ INFO] Gogs 0.11.66.0916
Apr 09 15:51:55 ubuntu1804 gogs[6882]: 2019/04/09 15:51:55 [ INFO] Cache Service Enabled
Apr 09 15:51:55 ubuntu1804 gogs[6882]: 2019/04/09 15:51:55 [ INFO] Session Service Enabled
Apr 09 15:51:55 ubuntu1804 gogs[6882]: 2019/04/09 15:51:55 [ INFO] SQLite3 Supported
Apr 09 15:51:55 ubuntu1804 gogs[6882]: 2019/04/09 15:51:55 [ INFO] Run Mode: Development
Apr 09 15:51:55 ubuntu1804 gogs[6882]: 2019/04/09 15:51:55 [ INFO] Listen: http://0.0.0.0:3000

Access Gogs Web Interface

Gogs is now installed and listening on port 3000. Open your web browser and type the URL http://192.168.0.100:3000/install (replace the IP address in the URL with your server IP address). You will be redirected to the Gogs web installation wizard as shown below:

Database settings

Gogs installation part 1

General Application Settings

Gogs installation part 2

Application Port, URL and Login

Gogs installation part 3

Now, provide all the required details like, database name, database username, password, application URL, admin username, password, run user and domain. Then, click on the Install Gogs button. Once the installation has been completed successfully, you should see the Gogs default dashboard in the following page:

Gogs GIT service dashboard

 

How to Install Gogs GIT Service on Ubuntu 18.04 LTS