Git is a must-have utility for programmers. It allows you to track code changes and easily share your code with others enabling remote collaboration. Online git services like GitHub, GitLab, and Bitbucket are nowadays accessible for everyone, though sometimes the need to self-host a private service arises.
Gogs is an open-source git server, light enough to run on a Raspberry Pi. It is written in Go Lang and provides pre-compiled binaries for arm architectures.
In this tutorial, we will install Gogs on a Raspberry Pi 2. So, first, connect to your Raspberry, and let’s start!
Update your system
To start with, update our system and install any missing dependencies.
sudo apt update
sudo apt install wget unzip git -y
Prepare for installation
We will create a special user called git to operate the Gogs server. The following command will create the user and disable his password:
sudo adduser --system --shell /bin/bash --gecos "User for managing of gogs server" --group --disabled-password --home /home/git git
The next thing we will have to do is to download the pre-compiled Gogs package. Check the latest versions available at https://dl.gogs.io/. At the time of writing this report the latest version is 0.12.3 so we downloaded the gogs_0.12.3_linux_armv7.zip
package (armv7architecture is compatible with Raspberry Pi 2, 3, and 4).
sudo su -c 'su git -c "wget https://dl.gogs.io/0.12.3/gogs_0.12.3_linux_armv7.zip -O ~/gogs_download.zip"'
After the download completes, unzip the package and then you may delete it.
sudo su -c 'su git -c "unzip ~/gogs_download.zip -d ~/"'
sudo su -c 'su git -c "rm ~/gogs_download.zip"'
Start the server
Now let’s setup the Gogs service to manage the server. Download the service script from the Gogs repo:
sudo wget https://raw.githubusercontent.com/gogs/gogs/main/scripts/systemd/gogs.service -O /lib/systemd/system/gogs.service
And then, enable the service and run it.
sudo systemctl enable gogs
sudo service gogs start
Follow the web installer
Now browse to the installation located at http://<your-raspbery-ip>:3000/install
and complete the installation steps.