GitLab allows you to create a private GitHub-like server at home, on your Raspberry Pi
Since the acquisition of GitHub by Microsoft you are many to worry about data privacy
A lot of companies have moved to other platforms, and the cheapest solution for individuals is to use their own private Git server
How to install GitLab on your Raspberry Pi?
GitLab has an apt repository dedicated to Raspberry Pi, so the installation is straightforward
Install the dependencies, like postfix, add the repository and install the main package
Then you can use the web interface and the git server for your projects
In this post, I’ll start with an introduction about Git and GitLab and why you need to use it
Then I’ll show you how to install GitLab and how to use the basic functions from this software
GitLab introduction
Git reminder
Git is a code manager, to share sources between all developers from a same project
It allows concurrent editing of the same files, and even if you are alone, it’s a good tool to back up your code and note the changes you make
If you know them, the goal is the same as with SVN (Subversion) or CVS (concurrent version system)
The main difference is that Git doesn’t need a main server to keep files, but it’s using the developers computers to store this
You should however install git on a server to make sure your code is safe if you are the only developer
GitLab presentation
GitLab is precisely the missing server in the default Git architecture
It provides you a backup host with a web interface to manage your project
At the beginning GitLab was just a tool to see your source code on a web interface
But since then, GitLab didn’t stop adding new features to this product in order to make it an essential tool in any Git project
GitLab is a free and open source software
But you can use it in the cloud if you prefer, for a price between 0 and $99
In this tutorial, I’ll show you how to install it for free on your Raspberry Pi
Why not use GitHub instead?
GitHub is a fantastic service to manage your Git repositories
But as I already said, you don’t control what they do with your source code and your information
For small projects, GitHub is fine, you can get an hosting for your source code for free and quickly
For bigger projects or for companies I don’t know if it’s always the best option
You can’t be sure that your data is safe, especially since Microsoft is in charge
GitLab also provides more and more tools to manage your project
For example, permissions management is more accurate on GitLab. This allows you to add not only developers on GitLab, but all kind of people that need to work on the project
GitLab installation
Prepare your system
To follow this tutorial, your Raspberry Pi needs to use Raspbian
Any version will be fine, Raspbian Lite is enough as we don’t need an interface to install GitLab
If you need help on how to install Raspbian on Raspberry Pi, click on the link, this is a step-by-step installation guide for beginners, all you need is in this guide
Once the Raspbian installation is complete, follow these last steps to achieve the system preparation:
- Enable SSH if not already done
sudo raspi-config
Then go to “Interfacing options” > “SSH” and choose “Yes”
- Update your system
sudo apt update sudo apt upgrade sudo reboot
- After the reboot you are ready to move to the next step
Install dependencies
GitLab needs some dependencies before the repository installation
For example, we need curl to download the repository key and postfix to send email notifications with GitLab
Here is the command to install all of them:
sudo apt install curl openssh-server ca-certificates apt-transport-https postfix
Type “Y” to continue
In the Postfix configuration, choose “Internet site” and enter your DNS name if you have one
You can change this later if you want email notifications, not a big deal, continue the installation
Add the GitLab repository
- Start by adding the apt key for the repository
curl https://packages.gitlab.com/gpg.key | sudo apt-key add -
- Then run the script to add the repository automatically
sudo curl -sS https://packages.gitlab.com/install/repositories/gitlab/raspberry-pi2/script.deb.sh | sudo bash
If everything goes fine, you get the success message “The repository is setup! You can now install packages.”
Install the GitLab package
We can finally install the GitLab package with:
sudo EXTERNAL_URL="http://192.168.1.15" apt install gitlab-ce
Replace the EXTERNAL_URL value by your IP address or the DNS name you want to use (don’t set a HTTPS URL for the moment)
The package weights 500Mb so it can take a few minutes to download it with low connection speed
And the installation also takes a long time to unpack and install GitLab
Don’t be afraid by all the messages appearing on your screen, it’s … normal
My Raspberry Pi 3B+ has almost crashed during the installation process (40 in load average) and I got an error (timeout)
If you have the same issue, restart the installation with: sudo apt install -f
First login
Once the installation is done, you can access the web interface on http://<EXTERNAL_URL>
Use the same URL as defined in the installation process
Log into the interface with:
- Login: root
- Password: It will prompt you to create one on your first visit
If you need more information about the GitLab configuration, you can find all the answers in the GitLab docs
GitLab usage
Fix error 502
If you are not able to access the web interface, because of a high load average, I got the same issue
I had something like 40 of load average, just to display one page, and a lot of timeout
I cross my fingers because I’m not sure it’s definitive
But since I increased my swap size, it seems to go better
To increase your swap size you need to follow these steps:
- Disable the swap usage
sudo dphys-swapfile swapoff
- Edit this file
sudo nano /etc/dphys-swapfile
- Change the value of the swap size
CONF_SWAPSIZE=2048
- Confirm the change (creation of the new file)
sudo dphys-swapfile setup
- Then enable the swap again
sudo dphys-swapfile swapon
Maybe you need a reboot to apply changes in the GitLab apps
Create your first project
Once logged in the GitLab interface, you will get a home page like this:
Click on “Create a project” and fill the form
Choose the options that fit the best to what you want to do and click on “Create project”
You can also use a template or import an existing Git project
Once the project is created (I got another laggy moment here, but it works), you can use it as usual with the git command
The project interface is really close from what you get on GitHub
For example, to clone my test project on my other Raspberry Pi:
git clone http://192.168.1.15/root/test.git
Related questions
Is it a good idea to use GitLab on a Raspberry Pi? It seems to work fine once the optimization issues were fixed. But I’m not sure it’s the best idea. It’s good for a try, to make sure you can do what you want with it. But for the long term, you need to find a more powerful device, and with less corruption risk (SD card is not the safer storage)
Where is the GitLab configuration file? To what I found, everything seems to be in the /etc/gitlab/gitlab.rb file. Options are not always intuitive, but you should find help on the GitLab website and forum
Conclusion
That’s it, you know how to install GitLab on your Raspberry Pi and how to use it
It’s a cool alternative to GitHub if you worry about data privacy and want to keep the control
But don’t forget to make backups if you don’t want to take the risk of losing everything
Check my guide on how to back up your Raspberry Pi if you need more information about that