How to install and configure Gogs on Ubuntu 18.04

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

Gogs is a lightweight application and can be installed on low-power systems. If you are looking for an alternative that takes up less memory than Gitlab and does not require the fancy features of Gitlab, then you must try Gogs.

This guide describes the steps to install and configure Gogs on Ubuntu 18.04. The same instructions apply to Ubuntu 16.04 and any other Ubuntu-based distributions.

1. Before you start##

Gogs can use SQLite, PostgreSQL and MySQL/MariaDB databases to store its data.

In this guide, we will use SQLite as the database. If SQLite is not installed on your system, you should enter the following command to install it:

sudo apt install sqlite3

For more security, we recommend setting up a basic firewall.

Two, install Gogs

We will install Gogs from binary. The installation process is very simple and straightforward.

2.1 Install Git

The first step is to install Git on your server. To do this, log in to the system as a sudo user, refresh the local package index, and install the git package with the following command:

sudo apt update
sudo apt install git

Verify the installation process by displaying the Git version:

git --version
git version 2.17.1

2.2 Create a Git user###

Create a new system user, run the Gogs service, enter:

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

This command will create a user and set the user folder to /home/git. The output will look like this:

Adding system user `git' (UID 111) ...
Adding new group `git' (GID 116)...
Adding newuser`git' (UID 111) with group `git' ...
Creating home directory `/home/git' ...

2.3 Download Gogs Binary Package###

Browse Gogs download page and download the latest binary package according to your system architecture. At the time of writing this article, the latest version is 0.11.86. If a new version is available, you should modify the value of the VERSION field in the following command.

Use the wget command to download the Gogs compressed file to the /tmp directory:

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

Once the download is complete, unzip 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 modify the attribution user and attribution user group of the Gogs installation directory to git:

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

2.4 Create a systemd unit file###

Gogs comes with Systemd unit files to facilitate our installation and configuration.

Copy this file to the /etc/systemd/system/ directory, enter:

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

Once completed, start and enable the Gogs service:

sudo systemctl start gogs
sudo systemctl enable gogs

Verify that the service has been successfully started:

* gogs.service - Gogs
 Loaded:loaded(/etc/systemd/system/gogs.service; enabled; vendor preset: enabled)
 Active:active(running) since Thu 2019-04-2504:13:44 PDT; 9s ago
 Main PID:14376(gogs)
 Tasks:8(limit:2319)
 CGroup:/system.slice/gogs.service
   `- 14376 /home/git/gogs/gogs web

2.5 Use the web installer to install Gogs

Download Gogsi has been downloaded and running, it is time to complete the entire installation process through the web interface.

Open your browser, enter: http://YOUR_DOMAIN_IR_IP:3000, the following screen will appear:

Database settings:

Apply general settings:

Once completed, click the "Install Gogs" button. The installation will proceed immediately, and when the installation is complete, you will be redirected to the login page.

Click "Sign up now":

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

that's it. Gogs has been installed on your Ubuntu machine.

2.6 Configure Nginx as an SSL proxy server###

This step is optional, but we strongly recommend it. To use Nginx as a reverse proxy server, you need to have a domain name or subdomain name pointing to your server's public IP. In this guide, we use gogs.example.com.

First, install Nginx and follow the guide below to generate a free Let's Encrypt SSL certificate:

Once done, open your text editor and edit the domain name server block:

sudo nano /etc/nginx/sites-enabled/gogs.example.com

server {
 listen 80;
 server_name gogs.example.com;

 include snippets/letsencrypt.conf;return301 https://gogs.example.com$request_uri;}

server {
 listen 443 ssl http2;
 server_name gogs.example.com;

 proxy_read_timeout 720s;
 proxy_connect_timeout 720s;
 proxy_send_timeout 720s;

 client_max_body_size 50m;

 # Proxy headers
 proxy_set_header X-Forwarded-Host $host;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
 proxy_set_header X-Real-IP $remote_addr;

 # SSL parameters
 ssl_certificate /etc/letsencrypt/live/gogs.example.com/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/gogs.example.com/privkey.pem;
 ssl_trusted_certificate /etc/letsencrypt/live/gogs.example.com/chain.pem;
 include snippets/letsencrypt.conf;
 include snippets/ssl.conf;

 # log files
 access_log /var/log/nginx/gogs.example.com.access.log;
 error_log /var/log/nginx/gogs.example.com.error.log;

 # Handle / requests
 location /{
  proxy_redirect off;
  proxy_pass http://127.0.0.1:3000;}}
 Don't forget to gogs.example.Replace com with your domain name and set the correct SSL certificate file location. All HTTP requests will be redirected to HTTPS.

Restart Nginx service to make the modification effective:

sudo systemctl restart nginx

Next, we will modify the Gogs domain name and root address. To do this, open the configuration file and edit the following line:

sudo nano /home/git/gogs/custom/conf/app.ini
[ server]
DOMAIN           = gogs.example.com
ROOT_URL         = https://gogs.example.com/

To restart the Gogs service, enter:

sudo systemctl restart gogs

At this point, Gogs is configured and you can access it: https://gogs.example.com.

2.7 Configure email notification###

For Gogs to be able to send notification emails, you need to install Postfix or use some other business email services, such as SendGrid, MailChimp, MailGun or SES.

To enable email notification, open the configuration file and edit the following line:

sudo nano /home/git/gogs/custom/conf/app.ini
[ mailer]
ENABLED =true
HOST    = SMTP_SERVER:SMTP_PORT
FROM    = SENDER_EMAIL
USER    = SMTP_USER
PASSWD  = YOUR_SMTP_PASSWORD

Make sure you put in the correct SMTP server information.

Restart the Gogs service to make the application take effect:

sudo systemctl restart gogs

Gogs also allows you to connect to Slack by creating web hook, and send notifications to your Slack channel.

Three, upgrade Gogs

To upgrade Gogs, some manual steps are required.

  1. The first step is to stop the Gogs service:
sudo systemctl stop gogs
  1. Rename the Gogs installation directory.
sudo mv /home/git/gogs{,_old}
  1. Download the latest version of Gogs and move it to the /home/git directory:
VERSION=
wget https://dl.gogs.io/${VERSION}/gogs_${VERSION}_linux_amd64.tar.gz -P /tmp
sudo tar xf /tmp/gogs_*_linux_amd64.tar.gz -C /home/git

Make sure you change VERSION to your actual Gogs release version.

  1. Use the rsync command to copy the custom, data, and log directories to the unzipped directory:
sudo rsync -a /home/git/gogs_old/{custom,data,log}/home/git/gogs/
  1. Finally, start the Gogs service:
sudo systemctl restart gogs

that's it.

Four, summary##

This tutorial takes you through the installation and configuration of Gogs on Ubuntu 18.04.

You can create your first project and start using your new Gogs server.

Recommended Posts

How to install and configure Gogs on Ubuntu 18.04
How to install and configure NATS on Ubuntu 16.04
How to install and configure Cyberpanel on Ubuntu 18.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure GitLab on Ubuntu 18.04
How to install and configure Ansible on Ubuntu 18.04
How to install and configure Elasticsearch on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
How to install and configure VNC on Ubuntu 18.04
How to install and configure Sphinx on Ubuntu 16.04
How to install and configure OrientDB on Ubuntu 14.04
How to install and configure AppScale on Ubuntu 12.04
How to install and configure PostGIS on Ubuntu 14.04
How to install Pycharm and Ipython on Ubuntu 16.04/18.04
How to install and configure Elasticsearch on CentOS 7
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and use Docker on Ubuntu 20.04
How to install and configure VNC on CentOS 8
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
How to install and use Wine on Ubuntu 18.04
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and configure Redis on CentOS 8
How to install and use Composer on Ubuntu 20.04
How to install and use BaasBox on Ubuntu 14.04
How to install and use PostgreSQL on Ubuntu 16.04
How to install and configure phpMyAdmin on CentOS 6
How to install and configure Owncloud on CentOS 8
How to install and use Docker on Ubuntu 16.04
How to install and configure Redmine on CentOS 8
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Nginx on Ubuntu 20.04
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
Install and configure MySQL on Ubuntu
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
How to install Memcached on Ubuntu 18.04
How to install Jenkins on Ubuntu 16.04
How to install MemSQL on Ubuntu 14.04
How to install Go on Ubuntu 20.04
How to install MongoDB on Ubuntu 16.04
How to install Mailpile on Ubuntu 14.04
How to install PrestaShop on Ubuntu 16.04
How to install Skype on Ubuntu 20.04
How to install Jenkins on Ubuntu 20.04
How to install Python 3.8 on Ubuntu 18.04
How to install KVM on Ubuntu 18.04
How to install KVM on Ubuntu 20.04
How to install opencv3.0.0 on ubuntu14.04