Learn how to – How To Install Gogs Git service on Ubuntu 22.04|20.04|18.04.
This tutorial will cover all the steps required to install Gogs self-hosted Git service on Ubuntu 22.04|20.04|18.04 server. Gogs project which is written in Go aims to build a simple, stable and extensible self-hosted Git service with a painless setup process. Gogs is distributed as an independent binary distribution and runs on all platforms that Go supports, including Linux, macOS, Windows, and ARM.
Gogs has excellent performance and is very light. It has very minimal RAM and CPU utilization. A VPS with 1 CPU core and 256MB RAM is enough to start using the service.
Features of Gogs
Gogs self-hosted Git service has the following set of features ( from Git )
- Activity timeline
- SMTP/LDAP/Reverse proxy authentication
- Account/Organization/Repository management
- Repository Git hooks/deploy keys
- SSH and HTTP/HTTPS protocols
- Reverse proxy with sub-path
- Add/Remove repository collaborators
- Web editor for repository files and wiki
- Migrate and mirror repository and its wiki
- Repository/Organization webhooks (including Slack and Discord)
- Repository issues pull requests, wiki, and protected branches
- Two-factor authentication
- Gravatar and Federated avatar with custom source
- Jupyter Notebook
- Administration panel
- Mail service
- Supports MySQL, PostgreSQL, SQLite3, MSSQL and TiDB (via MySQL protocol)
- Multi-language support (29 languages)
Gogs Open Source Components
Gogs components include:
- Web Framework: Macaron
- UI Components:
- Front-end Plugins:
- ORM: Xorm
- Database Drivers:
- And all other Go package dependencies
Install Gogs Git service on Ubuntu 22.04|20.04|18.04
Follow these steps to have Gogs installed on your Ubuntu server.
Step 1: Install MariaDB Database Server
Gogs requires a MySQL server to store data. We will install MariaDB server using the following commands:
sudo apt update
sudo apt install mariadb-server mariadb-client
Once the database server has been installed, login to MariaDB console as root user
sudo mysql -u root -p
Set global variables below
SET GLOBAL innodb_file_per_table = ON;
Then create gogs
database
DROP DATABASE IF EXISTS gogs;
CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
Create a dedicated database user to manage gogs
database.
GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost' IDENTIFIED BY "StrongPassword";
FLUSH PRIVILEGES;
q
Step 2: Download Gogs from Github
Check Gogs releases page https://github.com/gogs/gogs/releases for the latest release.
sudo apt install wget curl vim -y
curl -s https://api.github.com/repos/gogs/gogs/releases/latest | grep browser_download_url | grep 'linux_amd64.tar.gz' | cut -d '"' -f 4 | wget -i -
Extract the downloaded file
tar xvf gogs_*_linux_amd64.tar.gz
Step 3: Configure Gogs self-hosted Git service
Create git
user to run gogs service
$ sudo adduser git
Adding user `git' ...
Adding new group `git' (1001) ...
Adding new user `git' (1001) with group `git' ...
Creating home directory `/home/git' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for git
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
Create logs directory
sudo mkdir /var/log/gogs
sudo chown -R git:git /var/log/gogs/
Copy gogs
systemd service file to /etc/systemd/system
directory
sudo cp gogs/scripts/systemd/gogs.service /etc/systemd/system
You can edit the file to set customize the settings:
sudo vim /etc/systemd/system/gogs.service
If you have a different service using port,3000
you can set a custom port
ExecStart=/home/git/gogs/gogs web -port 3001
Move the gogs directory content inside /home/git
sudo mv gogs /home/git/
Change ownership of /home/git/
to user.git
sudo chown -R git:git /home/git/
Reload systemd and start gogs
service
sudo systemctl daemon-reload
sudo systemctl start gogs
Enable the service to start on boot
sudo systemctl enable gogs
You can check service status by running
$ systemctl status gogs
● gogs.service - Gogs
Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-05-08 09:14:51 UTC; 11s ago
Main PID: 2592 (gogs)
Tasks: 5 (limit: 4537)
Memory: 34.9M
CPU: 260ms
CGroup: /system.slice/gogs.service
└─2592 /home/git/gogs/gogs web -port 3001
May 08 09:14:51 jammy gogs[2592]: 2023/05/08 09:14:51 [TRACE] Log mode: Console (Trace)
May 08 09:14:51 jammy gogs[2592]: 2023/05/08 09:14:51 [ INFO] Gogs 0.13.0
May 08 09:14:51 jammy gogs[2592]: 2023/05/08 09:14:51 [TRACE] Work directory: /home/git/gogs
May 08 09:14:51 jammy gogs[2592]: 2023/05/08 09:14:51 [TRACE] Custom path: /home/git/gogs/custom
May 08 09:14:51 jammy gogs[2592]: 2023/05/08 09:14:51 [TRACE] Custom config: /home/git/gogs/custom/conf/app.ini
May 08 09:14:51 jammy gogs[2592]: 2023/05/08 09:14:51 [TRACE] Log path: /home/git/gogs/log
May 08 09:14:51 jammy gogs[2592]: 2023/05/08 09:14:51 [TRACE] Build time: 2023-02-25 02:30:34 UTC
May 08 09:14:51 jammy gogs[2592]: 2023/05/08 09:14:51 [TRACE] Build commit: 8c21874c00b6100d46b662f65baeb40647442f42
May 08 09:14:51 jammy gogs[2592]: 2023/05/08 09:14:51 [ INFO] Run mode: Development
May 08 09:14:51 jammy gogs[2592]: 2023/05/08 09:14:51 [ INFO] Available on http://localhost:3001/
Typing command gogs on the terminal as git user should print help page.
$ /home/git/gogs/gogs
NAME:
Gogs - A painless self-hosted Git service
USAGE:
gogs [global options] command [command options] [arguments...]
VERSION:
0.13.0
COMMANDS:
web Start web server
serv This command should only be called by SSH shell
hook Delegate commands to corresponding Git hooks
cert Generate self-signed certificate
admin Perform admin operations on command line
import Import portable data as local Gogs data
backup Backup files and database
restore Restore files and database from backup
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
Step 4: Configure Gogs self-hosted Git service
Open the URL http://serverip:3001/install to finish the installation of Gogs
Set database authentication
The username and password provided should match the ones provided in the Database configuration section. If the database server is on a different host, provide the IP address under the Host section.
Set Application General Settings
Provide application URL, this can be a routable server IP address or domain name that resolves to the IP. The same should be set for SSH.
Disable User self-registration
You can disable User self-registration under “Server and Other Services Settings”. This means the admin user will manually create user accounts.
You can optionally create an admin user account. By default, root user will gain admin access automatically.
When done with the configurations, click the “Install Gogs” button to finish the installation. On a successful installation, you should be logged into Gogs administration console.
Create additional user accounts
To add user accounts, Open Admin Panel at the top right panel
You can then use “Create New Account” link to add a new user to Gogs.
Step: 5 Test Gogs self-hosted Git service
Create a new repository called test-repo
Try cloning the repo
$ git clone http://192.168.18.40:3000/jmutai/test-repo.git
Cloning into 'test-repo'...
Username for 'http://192.168.18.40:3000': jmutai
Password for 'http://jmutai@192.168.18.40:3000': <Enter Password>
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done
To avoid Password Authentication, add your SSH public key under “Your Profile > SSH keys > Add Key
Provide key name, and paste your SSH public key into the content box.
An ssh git clone should not ask for a password
$ git clone git@192.168.18.40:jmutai/test-repo.git
Cloning into 'test-repo'...
Warning: Permanently added '192.168.18.40' (ECDSA) to the list of known hosts.
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (4/4), done.
Step 6: Configure Nginx Reverse Proxy
If you would like to access Gogs using a domain name without a port, you need to configure Apache or NGINX reverse proxy
sudo apt install nginx
Create a VirtualHost reverse proxy configuration file
sudo vim /etc/nginx/conf.d/gogs.conf
Add:
server {
listen 80;
server_name git.example.com;
location / {
proxy_pass http://localhost:3000;
}
}
If using SSL and would like to have http
to https
redirect, use:
server {
listen 80;
server_name git.example.com;
location / {
rewrite ^ https://git.example.com$request_uri? permanent;
}
}
server {
listen 443 ssl;
server_name git.example.com;
ssl_certificate /etc/letsencrypt/live/git.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/git.example.com/privkey.pem;
location / {
proxy_pass http://localhost:3000;
}
}
Replace git.example.com with your actual domain name. For more reading on Gogs administration and usage, check out the Official Documentation.
Related:
- How to disable GitLab User registration on Login page
- Configure GitLab FreeIPA LDAP Authentication
- How to Secure GitLab server with SSL certificate
Leave a Reply
You must be logged in to post a comment.