In this Raspberry Pi Gogs tutorial, we will be showing you how to set up the Gogs Git service on the Raspbian operating system.
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.
Here is all the equipment that I recommend for this Raspberry Pi Gogs tutorial.
Raspberry Pi 2, 3 or 4
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.
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.
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://dl.gogs.io/0.11.91/gogs_0.11.91_raspi_armv7.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.
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.
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.
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.).
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.
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.