How to install Gogs on Ubuntu 20.04

Gogs is a self-hosted open-source git server written in Go. It includes a repository file editor, project issue tracking, and a built-in wiki

Gogs is a lightweight application and can be installed on low-powered systems. If you are searching for an alternative to Gitlab with a much smaller memory footprint and you don’t need all the bells and whistles that Gitlab offers then you should definitely try Gogs.This tutorial covers the steps to install Gogs on Ubuntu 20.04.

Before You Begin

Gogs can use SQLite, PostgreSQL , or MySQL /MariaDB database to store all its data.

In this tutorial, we will use SQLite as the database of choice. If SQLite is not installed on your system you can install it by typing:

$ sudo apt install sqlite3

For an additional layer of security, it is recommended to set up a basic firewall. You can follow the steps in our How To Set Up a Firewall with UFW on Ubuntu guide

Installing Gogs

We will install Gogs from binary. The installation is a pretty straight forward process.

-Install Git

The first step is to install Git on your server. To do so, refresh the local package index and install the git package by running the following commands as sudo user :

$ sudo apt update
$ sudo apt install git

Verify the installation by displaying the Git version:

$ git --version

Output:

-Create a Git user:

Create a new system user to run the Gogs service by typing:

$ sudo adduser --system --group --disabled-password --shell /bin/bash --home /home/git --gecos 'Git Version Control' git

The command will create the user and set the home directory to /home/git. The output will look something like below:

Output:

Download Gogs binary

Visit the Gogs Download page and download the latest binary for your architecture. At the time of writing, the latest version is 0.11.86, if there is a new version available change the VERSION variable in the command below.

Download the Gogs archive in the /tmp directory using the following wget command :

$ VERSION=0.11.86
$ wget https://dl.gogs.io/${VERSION}/gogs_${VERSION}_linux_amd64.tar.gz -P /tmp

Once the download is completed, extract the Gogs tar.gz file and move it to the /home/git directory:

$ sudo tar xf /tmp/gogs_*_linux_amd64.tar.gz -C /home/git

Run the following command to change the ownership of the Gogs installation directory to the user and group git:

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

Create a systemd Unit File

Gogs comes with a Systemd unit file that is already configured to match our setup.

Copy the file to the /etc/systemd/system/ directory by typing:

$ sudo cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/

Once done, start and enable the Gogs service:

$ sudo systemctl start gogs
$ sudo systemctl enable gogs

 Successfully:

Install Gogs using the web installer

Now that Gogs is downloaded and running, it is time to finalize the installation through the web interface.

Open your browser, type http://your_ip:3000 and a screen similar to the following will appear:

Database Settings:
  • Database Type: SQLite3
  • Path: Use an absolute path, /home/git/gogs/gogs.db

Application General Settings

  • Application Name: Enter your organization name
  • Repository Root Path: Leave the default /home/git/gogs-repositories
  • Run User: git
  • Domain: Enter your domain or server IP address.
  • SSH Port: 22, change it if SSH is listening on other Port
  • HTTP Port: 3000
  • Application URL: Use http and your domain or server IP address.
  • Log Path: Leave the default /home/git/gogs/log

Once done hit the “Install Gogs” button. The installation is instant and when completed you will be redirected to the login page.

Click on the “Sign up now” link.

The first registered user is automatically added to the Admin group.

That’s it. Gogs has been installed on your Ubuntu machine.

Conclusion

This tutorial walked you through the installation Gogs on Ubuntu 20.04.

Good Luck!

 

On this page