GitLab allows you to create a private GitHub-like server at home on your Raspberry Pi.
Since the acquisition of GitHub by Microsoft, many worry about data privacy. Many companies moved to other platforms, and the cheapest solution for individuals is to use a private Git server (on Raspberry Pi for example).
To install GitLab on a Raspberry Pi, there is an official repository to register in the APT configuration.
Then it can be installed with the command line: apt install gitlab-ce.
In this post, I’ll begin with an introduction about Git and GitLab and why you need to use them.
Then, I’ll show you how to install GitLab and how to use the basic functions of this software.
If you are looking for quick progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge, where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.
If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)!
Git is a code manager used to share sources between all developers from the 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 require a main server to keep files. Git uses the developers’ computers to store files instead.
However, you should install Git on a server to make sure your code is safe if you are the only developer.
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.
In the beginning, GitLab was just a tool to see your source code on a web interface.
But since then, GitLab continued adding new features 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 can’t control what they do with your source code and your information.
For small projects, GitHub is fine, you can get quickly get free hosting for your source code.
For bigger projects or for companies, I don’t know if it’s 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 kinds of people that need to work on the project.
Prepare your system
To follow this tutorial, your Raspberry Pi needs to use Raspberry Pi OS.
Any version will be fine, Raspberry Pi OS Lite is enough as we don’t need an interface to install GitLab.
If you need help on how to install Raspberry Pi OS on Raspberry Pi, follow my step-by-step installation guide for beginners.
Once the Raspberry Pi OS installation is complete, follow these last steps to achieve the system preparation:
- Enable SSH if not already done:
- Then go to “Interfacing options” > “SSH” and choose “Yes”.
- Update your system:
sudo apt update
sudo apt upgrade
- After the reboot, you will be ready to move to the next step.
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 bashIf everything goes fine, you will 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 with your IP address or the DNS name you want to use (don’t set an HTTPS URL for the moment).
The package weighs 500Mb so it can take a few minutes to download it with low connection speed.
The installation takes a long time to unpack and install GitLab.
Don’t be afraid by all the messages that appear 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
Login on the GitLab interface
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.
Fix error 502
If you aren’t able to access the web interface because of a high load average, I had the same issue.
I had something like 40 of load average, just to display one page and a lot of timeouts.
I cross my fingers because I’m not sure it’s definitive.
But once I increased my swap size, it seemed to work 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:
- Confirm the change (creation of the new file):
sudo dphys-swapfile setup
- Then enable the swap again:
sudo dphys-swapfile swapon
You might need a reboot to apply changes in the GitLab apps.
Sale: 10% off today.
Get the eBook.
Do more with your Raspberry Pi, learn the useful concepts and take the shortcuts.
You miss half of the fun of using a Raspberry Pi if you don’t know anything about Python.
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
Grab your free PDF file with all the commands you need to know on Raspberry Pi!
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 to try in order 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? From 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.
Want to be a part of the RaspberryTips community? Join us here and get access to behind-the-scenes content, my thoughts and more while supporting me to continue posting on this website.
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 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.