In this Raspberry Pi Gogs tutorial, we will be showing you how to set up the Gogs Git service on the Raspbian operating system.

Raspberry Pi Gogs
Gogs is a performance-friendly Git web interface written in the Go programming language. It makes setting up and managing GIT repositories on the Raspberry Pi a simple process.

You will find that Gogs is one of the best choices for setting up a self-hosted Git web interface on the Raspberry Pi thanks to its relatively low memory footprint.

The Gogs software also sports an interface that is very much like Github’s, making it a simple switch if you are used to its web interface but want a self-hosted Git solution.

Equipment List

Here is all the equipment that I recommend for this Raspberry Pi Gogs tutorial.

Recommended

Raspberry Pi 2, 3 or 4

Micro SD Card

Power Supply

Ethernet Cord or WiFi dongle (The Pi 3 and 4 has WiFi inbuilt)

Optional

Raspberry Pi Case

Preparing for Gogs on the Raspberry Pi

1. Our first task is to update the packages on our Raspberry Pi. Updating helps prepare our Raspberry Pi for installing and setting up Gogs.

Run the following two commands on your Raspberry Pi to update the package list and packages.

sudo apt update
sudo apt upgrade

2. With our Raspberry Pi up to date, we can now go ahead and install all the packages that we will be relying on for the Gogs software.

The two packages we are interested in installing is the MariaDB MySQL server and the Git software.

sudo apt install mariadb-server git unzip

3. Now with a MySQL server installed we need to now set that up for use with Gogs.

To start with we need to secure the installation, we can do that by running the command below.

sudo mysql_secure_installation

Follow the prompts to set a password for the “root” user and secure the MySQL installation.

Make sure you remember the password that you defined for the “root” user as you will need that later.

4. We need to now log in to the MySQL command-line interface by running the command below.

sudo mysql -u root -p

5. Let’s first create a database within this MySQL interface by running the following command.

We will be calling this database “gogs” as we will be using it with the Gogs software.

CREATE DATABASE gogs;

6. Next, we will create a user that has all privileges to interact with our “gogs” database. We will be calling this user “goguser” and assigning it the password “pimylifeup

Make sure you replace the password with something a bit more secure, make a note of what you set.

Run the command below in the MySQL interface to create the user and assign it privileges.

GRANT ALL PRIVILEGES ON gogs.* TO 'goguser'@'localhost' IDENTIFIED BY 'pimylifeup';

7. As we created a new user and assigned privileges, we need to flush the privilege table.

FLUSH PRIVILEGES;

8. With that done you can now exit out of the MySQL command line by typing in “exit“.

9. One of the last things we need to do to prepare for Gogs is to create a user for it to run as.

We will be naming this user “git” and using “–disabled-login” so that no one can log in using this user.

sudo adduser --disabled-login git

We can now move on to downloading and setting up Gogs on our Raspberry Pi. We will be making use of the database and user we created in this section.

Installing Gogs on the Raspberry Pi

1. Now that we have set up our MySQL database for Gogs, we can now proceed to download and run the Gogs software.

Let’s now download the Gogs software to the “/home/git” directory by running the commands below.

cd /home/git
sudo wget https://cdn.gogs.io/0.11.86/gogs_0.11.86_raspi2_armv6.zip -O gogs.zip
sudo unzip gogs.zip
sudo rm gogs.zip

2. With Gogs now downloaded and unzipped, let’s go ahead and use the “chown” command to make sure that the git user has rights over all the files we just created

sudo chown -R git:git /home/git

3. Next, we can go ahead and enable the Gogs service file that came with our Gogs installation.

By running the command below, systemctl will run the service file when the system starts up.

sudo systemctl enable /home/git/gogs/scripts/systemd/gogs.service

4. Finally, let’s start up the service that we just enabled. This command will fire up Gogs web service, and it will immediately become accessible.

You can do enable the Gogs service by running the command below.

sudo systemctl start gogs.service

5. To ensure Gogs service has started up correctly, we need to go ahead and run the command below.

This command will retrieve the status of the service from the systemctl service manager.

sudo systemctl status gogs.service

If the status command shows “Active: active (running)” then everything is running correctly.

6. Finally, we should grab our Raspberry Pi’s local IP address by running the command below. You might want to setup a static IP, so it’s easier to remember.

hostname -I

Configuring Gogs on the Raspberry Pi

1. In your favorite web browser, go to the following address. Make sure you swap “<IPADDRESS>” with the IP address of your Raspberry Pi Gogs installation.

This will take you to Gogs web interface.

http://<IPADDRESS>:3000

2. Upon first loading, the Gogs web interface, you will be first greeted with an initial setup screen.

This screen will ask you for several details to complete the Gogs installation.

First, we need to set the “Database Settings” (1.). Here we specify “gogsuser” for the database username. We also need to specify the “Password” for the user that you set earlier on in this tutorial.

Also, in the “Application General Settings” section, we need to replace the current “Domain” value (2.) with your Raspberry Pi’s local IP address.

GoGs Install Screen for Database and General Settings

3. Next, we need to update the “Application URL” (1.), replace “localhost” within this string with your Raspberry Pi’s IP address.

Now we need to set up an admin user for the Gogs interface. To do this, you must first click the “Admin account Settings” (2.) dropdown box to reveal the admin account options.

In the four text boxes that appear under the “Admin Account Settings” section (3.), enter in the various details to set up your admin account.

While you can skip this step and complete it later, it’s safer to complete it during the initial installation phase as whoever creates the first user becomes the admin.

Finally, once all the settings have been changed to your liking, go ahead and press the “Install Gogs” button (4.).

Gogs Install Screen for Optional Settings

4. Once the Gogs installation process has completed, you will be greeted by the following screen.

This screen means that Gogs has now been successfully setup on your Raspberry Pi, and you should now be able to create Git repositories through the web interface.

Gogs Dashboard

If Gogs doesn’t take your fancy, then there is always other solutions such as Gitea or even a much heavier GitLab. It all comes down to personal preference.

That’s all we have for setting up Gogs on the Raspberry Pi. If you have some feedback, tips, or anything else then please don’t hesitate to leave a comment below.

Get tutorials delivered to your inbox weekly.