How to Install and Configure Gogs on Ubuntu 22.04
Choose a different version or distribution
Introduction
Before we begin talking about how to install Gogs on Ubuntu 22.04, let’s briefly understand - What Gogs is?
Gogs is a self-hosted Git service that makes managing code repositories easy and efficient. Created with simplicity in mind, Gogs provides a lightweight and user-friendly interface, ensuring a hassle-free experience.
With its seamless integration with Git, Gogs allows developers to collaborate effortlessly on projects, enabling version control and code management. Whether you're an individual developer or part of a team, Gogs empowers you to streamline your development workflow and enhance productivity.
In this tutorial, you will install and configure Gogs on Ubuntu 22.04. We will also address some of the FAQs related to Gogs installation.
Advantages of Gogs
- Self-hosted Git service: Gogs allows you to host your own Git repositories, ensuring complete control and privacy over your code.
- Lightweight and user-friendly: With its intuitive interface, Gogs offers a simple and efficient way to manage your code repositories.
- Seamless Git integration: Gogs seamlessly integrates with Git, providing version control and easy collaboration on your projects.
- Enhanced productivity: Gogs streamlines your development workflow, enabling smooth code management and efficient collaboration among team members.
- Simplified code management: Whether you are an individual developer or part of a larger team, Gogs simplifies code management, making it easier to organize, track, and collaborate on codebase.
Prerequisites
- Gogs may use SQLite, PostgreSQL, or MariaDB database to store all its data.
- You will use SQLite as the database. Install by running the following command:
sudo apt install sqlite3
For the additional security, we recommend you set up a basic firewall.
Step 1- Installing Gogs
You will install Gogs from binary. It is a pretty straightforward process.
1) Firstly, install Git
on the server. For this, refresh the local package index and then install the git package. Do it by running the following commands as a sudo
user:
sudo apt update
sudo apt install git
2) Next, verify the installation by displaying the Git version:
git --version
You will get the below output:
Output
git version 2.33.1
3) Now, create a new system user and run the Gogs service by typing:
sudo adduser --system --group --disabled-password --shell /bin/bash --home /home/git --gecos 'Git Version Control' git
4) Here, the command will create the user and set the home directory to /home/git
. The output will look like below:
Output
Adding system user `git' (UID 111) ...
Adding new group `git' (GID 116) ...
Adding new user `git' (UID 111) with group `git' ...
Creating home directory `/home/git' ...
5) Now, visit the Gogs Download page and download the latest binary for architecture. The latest version is 0.13.0
, if there is a new version available, change the VERSION
variable.
6) Now, download the Gogs archive in the /tmp
directory. Use the following wget
command:
VERSION=0.11.86
wget https://dl.gogs.io/${VERSION}/gogs_${VERSION}_linux_amd64.tar.gz -P /tmp
7) After downloading, extract the Gogs tar.gz
file. Move it to the /home/git
directory using the below command:
sudo tar xf /tmp/gogs_*_linux_amd64.tar.gz -C /home/git
8) To change the ownership of the Gogs installation directory to the user and group git, run:
sudo chown -R git: /home/git/gogs
Create a systemd Unit File
1) Now, you will create a systemd
Unit File. Gogs comes with a systemd
unit file already configured to match the setup.
Copy the file to /etc/systemd/system/
directory by command:
sudo cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/
2) After that, start and enable the Gogs service, using the below command:
sudo systemctl start gogs
sudo systemctl enable gogs
3) Now, verify that the services start successfully:
Output
* gogs.service - Gogs
Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-04-25 04:13:44 PDT; 9s ago
Main PID: 14376 (gogs)
Tasks: 8 (limit: 2319)
CGroup: /system.slice/gogs.service
`-14376 /home/git/gogs/gogs web
Gogs Installation using a Web Installer
1) Open your browser, then type http://YOUR_DOMAIN_IR_IP:3000
. A setting screen will appear.
2) Now, do the database Settings:
- Database Type- SQLite3
- The path will be an absolute path,
/home/git/gogs/gogs.db
Application General Settings
- Application Name will be your organization name
- For repository root path- Leave the default
/home/git/gogs-repositories
- Run User- git
- Domain- Enter the domain or server the IP address
- SSH Port- 22, change if the SSH is listening on other Port
- The HTTP Port- 3000
- For Application URL- Use http and your domain or server IP address
- For the log path- leave the default
/home/git/gogs/log
3) After that, hit the “Install Gogs” button, where the installation is basically instant. After it gets complete, you will be redirected to the login page.
4) Click on the “Sign-up now” link.
The first registered user automatically gets added to the Admin group.
Step 2- Configuring Nginx as SSL Termination Proxy
1) To use Nginx as a reverse proxy you will need a domain or subdomain pointing to your server's public IP. So first, install Nginx
. Then you will generate a free Let’s Encrypt SSL certificate as per the guidelines below:
2) After this, open your text editor. You will need to edit the domain server block file:
sudo nano /etc/nginx/sites-enabled/gogs.example.com
server {
listen 80;
server_name gogs.example.com;
include snippets/letsencrypt.conf;
return 301 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;
}
}
3) Now, restart the Nginx service for the changes to take effect:
sudo systemctl restart nginx
4) Next, you will need to change the Gogs domain and the root URL. For this, open the configuration file and edit the following lines:
sudo nano /home/git/gogs/custom/conf/app.ini
[server]
DOMAIN = gogs.example.com
ROOT_URL = https://gogs.example.com/
5) Restart the Gogs service by running:
sudo systemctl restart gogs
6) Now the configuration of the Gogs is complete. You can access it at: https://gogs.example.com
Step 3- Configuring the Email Notifications
1) For Gogs to enable to send notification emails, you can install Postfix. You can also do it by using transactional mail services like SendGrid, MailChimp, MailGun, or the SES.
2) So to enable email notifications, open the configuration file and edit the following lines:
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
3) You need to make sure to put the right SMTP server information.
4) Then, restart the Gogs service for changes to take place:
sudo systemctl restart gogs
5) Gogs will also allow you to connect to Slack by creating a web webhook. It sends the notification to your Slack channels.
Step 4- Upgrading Gogs
1) To upgrade Gogs, it needs manual steps. Firstly, you need to stop the Gogs service:
sudo systemctl stop gogs
2) Next, rename the Gogs installation directory using the following command:
sudo mv /home/git/gogs{,_old}
3) Download the latest version of Gogs then move it to the /home/git
directory:
VERSION=<THE_LATEST_GOGS_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
4) Also, make sure to change VERSION
with the actual Gogs release version.
5) Now, copy the custom
, data
, log
directories to the extracted directory. Do it by using the following rsync command:
sudo rsync -a /home/git/gogs_old/{custom,data,log} /home/git/gogs/
6) Now, finally start the Gogs service:
sudo systemctl restart gogs
FAQs to Install Gogs on Ubuntu 22.04
What are the system requirements for installing Gogs on Ubuntu 22.04?
You will need a machine with at least 1GB of RAM and 500MB of free disk space to install Gogs on Ubuntu 22.04.
Can Gogs be accessed through a web browser?
Yes, Gogs provides a web-based user interface that can be accessed through any modern web browser.
Can I customize the Gogs installation on Ubuntu 22.04?
Yes, Gogs allows for customization through its configuration files, which can be modified according to your requirements.
How can I ensure the security of my Gogs installation on Ubuntu 22.04?
You can secure your Gogs installation by enabling HTTPS, using firewalls, regularly updating Gogs, and following security best practices.
Can Gogs be integrated with existing CI/CD tools?
Yes, Gogs can be integrated with various Continuous Integration and Continuous Deployment tools, offering a seamless development experience.
Is it possible to migrate existing repositories to Gogs on Ubuntu 22.04?
Yes, Gogs provides tools and documentation to help you migrate your repositories from other Git services to Gogs.
Conclusion
We hope this detailed guide helped you understand how to install Gogs on Ubuntu 22.04 server.
If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.