A Guide To Install Gogs on Ubuntu 22.04 — HostnExtra

HostnExtra Technologies
3 min readOct 21, 2022
A Guide To Install Gogs on Ubuntu 22.04 — HostnExtra
Install Gogs on Ubuntu 22.04 — HostnExtra

In this article, we’ll explain how to install Gogs on Ubuntu 22.04 with PostgreSQL database.

The Gogs (/gz/) project seeks to create a self-hosted Git service that is straightforward to set up, stable, and extendable. With Go, this is possible on every platform, including Linux, macOS, Windows, and ARM-based systems, with an independent binary distribution.

Prerequisites:

  • Git (bash): Version >= 1.8.3 for both server and client sides
  • A Ubuntu 22.04 installed KVM VPS or dedicated server.
  • A root user access or normal user with administrative privileges

Install Gogs on Ubuntu 22.04

Step 1 — User management

Add user

# adduser

It will ask you to enter the password for the new user.

Add user in sudo group

# usermod -aG sudo <username>

Login with new user

# su — <username>

Update the server:

# apt update -y

Step 2 — Install dependencies:

$ sudo apt install git gcc -y

Step 3 — Install Golang

We will download Go using wget command and extract it in /usr/local path.

At the time of writing this guide, the latest available version was 1.19. You can check the latest Go version from the Go official download page.

$ sudo wget https://golang.org/dl/go1.19.2.linux-amd64.tar.gz

$ sudo tar -zxvf go1.19.2.linux-amd64.tar.gz -C /usr/local

Setup Environment variables

The Go’s runtime and build executable are now available under /usr/local/go/bin. Add the executable path to PATH environment variable. Add the GOROOT environment variable referencing your local Go installation. Use the source command to reload the updated values.

$ sudo echo ‘export GOROOT=/usr/local/go’ | sudo tee -a /etc/profile

$ sudo echo ‘export PATH=$PATH:/usr/local/go/bin’ | sudo tee -a /etc/profile

$ sudo source /etc/profile

Verify the installation

To verify the installation, we can check the version of the Go by using following command:

$ go version

Output will show similar like:

go version go1.19.2 linux/amd64

Step 4 — Install PostgreSQL database

$ sudo apt install -y postgresql

Next, we need to create a database for Gogs and assign it a username and password for authentication.

# sudo -u postgres psql

postgres=# CREATE DATABASE gogs;

CREATE DATABASE

postgres=# CREATE USER gogs WITH PASSWORD ‘gogspassword’;

CREATE ROLE

postgres=# GRANT ALL PRIVILEGES ON DATABASE gogs TO gogs;

GRANT

postgres=# \q

Note:

Use database name, username, and password as per your choice.

Step 5 — Install and configure Gogs

First, download it using Git command:

$ sudo git clone — depth 1 https://github.com/gogs/gogs.git gogs

Change the working directory:

$ cd gogs/

Build Gogs:

$ sudo go build -o gogs

Start the server:

./gogs web

Now navigate to your browser and type your server IP with 3000 port. It will display following screen.

Install Gogs — HostnExtra

Here you need to enter PostgreSQL database name, username, and password that we have created on step 4. In the bottom of the page you can see the option to create a admin user.

Remember: Write the username which you have used for the installation in the “Run User”. We have created the user in step 1 otherwise it will give you an error.

Note: If you still get error of run user, check the permission or directory ownership of the Gogs directory. It should be your username.

We have explained how to install Gogs on Ubuntu 22.04 with PostgreSQL database.

--

--

HostnExtra Technologies

HostnExtra was founded in 2016. All of our servers are located in the continental United States and United Kingdom. View more details https://www.hostnextra.com