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.
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.
We will install Gogs from binary. The installation process is very simple and straightforward.
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
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' ...
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
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
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:
Application Name: Enter your organization name
Repository Root Path: leave the default value /home/git/gogs-repositories
Run User: git
Domain: Enter your domain name or server IP address.
SSH Port: 22, if your SSH monitors other ports, please modify it.
HTTP Port: 3000
Application URL: Use http and your domain name or server IP address.
Log Path: Leave the default value /home/git/gogs/log
You can also modify the settings later by editing the Gogs configuration file.
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.
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
.
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.
To upgrade Gogs, some manual steps are required.
sudo systemctl stop gogs
sudo mv /home/git/gogs{,_old}
/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.
custom
, data
, and log
directories to the unzipped directory:sudo rsync -a /home/git/gogs_old/{custom,data,log}/home/git/gogs/
sudo systemctl restart gogs
that's it.
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