HomeTutorialsHow to Install and Configure Gogs Git Service on Ubuntu Linux

How to Install and Configure Gogs Git Service on Ubuntu Linux

The Gogs is a compact and self-hosted hassle-free Git service that you can install on your Ubuntu Linux server and distribution to enjoy the Git facilities. The Gogs services are lightweight yet powerful; you can install the Gogs services on Docker, cloud server, and even on a Raspberry Pi system. Even old PC and hardware systems can handle the Gogs services. The Gogs is written in the Go language. The simple dashboard, custom domain support, HTTP security, and multi-database support of the Gogs Git Service will give you a comfortable setting to use the Git service on your Ubuntu system.

Gogs Git Service on Ubuntu Linux


Installing Gogs Git Service on Ubuntu Linux is not a complicated procedure, either not a quick process. You can install it on your machine and use the Gogs services through a domain or a localhost server. To get the Gogs services on your Ubuntu machine, you will need to install a database engine, an HTTP server, and the Git services on your system.

This post will see how you can install, configure, and get started with the Gogs services on a Ubuntu Linux system. If you have a Linux server, mostly a Ubuntu server running on your machine, installing Gogs can be a lot easier.

Step 1: Install Database on Ubuntu Linux


As the Gogs service requires a database engine, you can choose your favorite DB engine among MySQL, PostgreSQL, TiDB, and SQLite3 databases. Here, I will install PostgreSQL on my Ubuntu Linux system. You can run the following command-line given below to install the PostgreSQL on your Ubuntu system with root privileges.

sudo apt install -y postgresql postgresql-client libpq-dev

install postgres sql

Once PostgreSQL is installed on your system, you may now run the following system control commands to start and enable the database on your Ubuntu system. If you can’t find the default password of your PostgreSQL or find any issues, you can see this post to know how to set up and get started with PostgreSQL on Linux.

systemctl start postgresql
systemctl enable postgresql

Now, we have to create a database for the Gogs service on our Ubuntu system. You can now run the following commands to log in to your DB engine.

su - postgres
psql

After logging in, create a user, and set a new password for the database. I must mention, you should note down the database name and the password; you will need this information later to sign in to the Gogs dashboard.

CREATE USER git CREATEDB;
\password git

If your login is successful, you may now run the following SQL commands on your terminal shell to create a database for the Gogs git services on your Ubuntu system.

CREATE DATABASE gogs_production OWNER git;

postgress db on gogs

Step 2: Install Gogs on Ubuntu Linux


In this step, we will see the process of installing the Gogs service on our Ubuntu Linux. Now, we will download the compressed version of the Gogs service on our Linux filesystem. You need to install the Wget service on your Ubuntu system to get the Gogs file. If you already have the wget installed, you can just run the export and wget command-line is given below.

sudo apt install wget
export VER=0.11.86
wget https://github.com/gogs/gogs/releases/download/v${VER}/linux_amd64.tar.gz

After finishing the download, you can run the following tar command on your Ubuntu terminal shell to extract the compressed file.

tar xvf linux_amd64.tar.gz

Step 3: Configure GIT Git Service on Ubuntu Linux


After successfully installing the Gogs git service on our Ubuntu system, we will now install the Git service on our system. If you already have Git installed on your machine, you don’t need to install it again.

sudo apt install git

Now, add a new user to your Git service and assign a new password. Provide all the necessary information and complete the process of creating the new Git user on your Ubuntu system.

$ sudo adduser git

add user to git

After creating the new Git user, we will now make a new directory and give it the root access. Then we will copy the Gogs files inside the /etc/systemd/system directory. Run the following make directory command and ownership change commands given below on your terminal shell with root privileges.

sudo mkdir /var/log/gogs
sudo chown -R git:git /var/log/gogs/

Now, run the copy (cp) command on your terminal to copy the Gogs file inside the /etc/systemd/system directory.

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

We will now edit and configure the configuration settings of the Gogs service on our Ubuntu system. You can run the following command given below to edit the Gogs configuration script. Here, I am using the nano script editor; you can use any other script editor as well.

sudo nano /etc/systemd/system/gogs.service

gogs services on ubuntu

Now, copy the following script given below and replace the default script with it. You can make changes to the script if necessary.

[Unit]
Description=Gogs self-hosted Git service
After=syslog.target
After=network.target
After=mysql.service

[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
Type=simple
User=git
Group=git
WorkingDirectory=/home/git
ExecStart=/home/git/gogs web
Restart=always
Environment=USER=git HOME=/home/git

# Some distributions may not support these hardening directives. If you cannot start the service due
# to an unknown option, comment out the ones not supported by your version of systemd.
ProtectSystem=full
PrivateDevices=yes
PrivateTmp=yes
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

I must mention that the Gogs services use the network port 3000; if the port 3000 is already used in another service on your machine, you can assign any other network port for the Gogs service. To assign a new port, you can find the following line and replace the port.

ExecStart=/home/git/gogs web -port 3001

We will now copy the Gogs directory to the home/git directory and change the ownership. Run the following command-lines on your Ubuntu terminal shell to make the changes.

sudo rsync -avz gogs/* /home/git/
sudo chown -R git:git /home/git/

Step 4: Check Gogs Status on Ubuntu Linux


After installing and configuring the database and Gogs service on your Ubuntu Linux, you may now run the following system control commands given below to reload, start, and enable the Gogs services on your Ubuntu system.

sudo systemctl daemon-reload
sudo systemctl start gogs
sudo systemctl enable gogs

You can finally run the following system control command to check the Gogs services’ status on your Ubuntu Linux. If everything goes correct, you would see the activation status, main PID, tasks, and memory usages for the Gogs service on your terminal shell.

sudo systemctl status gogs

gogs system status on ubuntu

You can now switch to the git user from your current user and see the Gogs manual.

su - git
Password:
git@ubuntupit:~$ ./gogs

see gogs mannual

Step 5: Configure Gogs Git Service on Ubuntu Linux


Till now, we have successfully installed the Gogs service and created a Git user on our Ubuntu system. We will now find the IP address of our machine and use the IP address to load the Gogs setting page. You can run the following command-line on your terminal shell to find your IP address.

ip address

Using a static IP is better if you have to run a server or a web-based regularly on your machine. If you have the localhost server installed on your system, you can also use the localhost IP address to load the Gogs installation page on your Ubuntu Linux.

https://192.168.0.1:3000/install

setup gogs on ubuntu browser

Now, select your database, put the correct hosting address, and provide the username and password of the previously created database. You can also find the option to set the admin account at the bottom of the setting page. When the Gogs repository configuration is done, click on the Install button to finish the installation process.

When the installation is done, you will be redirected to a Sign In page. You can create a new account for Gogs, or you can log in instead.

log in git on firefox

After signing in to the Gogs git service on your Ubuntu Linux, you would see the simple dashboard of the Gogs system.

gogs dashboard

Step 6: Configure Nginx Server


You can use the Nginx reverse proxy server on your Ubuntu machine to use a custom domain for the Gogs service.  First, run the following command given below to install the Nginx server on your Ubuntu system.

sudo apt install nginx

Now, to configure your domain address and redirect your current Gogs service to your domain, run the following command on your terminal shell.

sudo nano /etc/nginx/conf.d/gogs.conf

Once the Nginx configuration script is opened, copy and paste the following lines inside your Nginx configuration script. You must replace the example.com domain with your own domain.

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

location / {
proxy_pass https://localhost:3000;
}
}

nginx server for gogs

Final Words


The Gogs service is helpful and user-friendly for new and old Linux users to stay connected with the Git service. In the entire post, I have described the method of installing the Gogs service on Ubuntu Linux. I have also shown how you can configure a personal domain for the Gogs service through the Nginx server on your Ubuntu system.

Though the Gogs is a lightweight tool, it won’t interrupt your other works on your Ubuntu machine. However, If you a regular Ubuntu user, you must update your Linux kernel; the latest kernel of Ubuntu is incredible.

Please share it with your friends and the Linux community if you find this post helpful and informative. We also encourage you to write down your opinions in the comment section.

Mehedi Hasan
Mehedi Hasan
Mehedi Hasan is a passionate enthusiast for technology. He admires all things tech and loves to help others understand the fundamentals of Linux, servers, networking, and computer security in an understandable way without overwhelming beginners. His articles are carefully crafted with this goal in mind - making complex topics more accessible.

LEAVE A REPLY

Please enter your comment!
Please enter your name here


You May Like It!

Trending Now