Setting up a Self-Hosted Git Server with Gitea (Raspberry Pi Guide)
Gitea is a lightweight, self-hosted Git service that runs efficiently on devices like the Raspberry Pi. This guide walks through installing and configuring Gitea on a Raspberry Pi 400 (ARM64) with MariaDB. It was originally written in 2023, so some commands may be outdated.
1. Install Git and Dependencies
sudo apt update && sudo apt upgrade -y
sudo apt install git mariadb-server wget -y
git --version
2. Create a Dedicated Git User
It’s not recommended to run Gitea as root. Create a dedicated system user instead:
sudo adduser \
--system \
--shell /bin/bash \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
git
3. Download and Configure Gitea
Download the correct binary for ARM64 from the official Gitea site and make it executable.
wget -O gitea https://dl.gitea.com/gitea/1.22.3/gitea-1.22.3-linux-arm64
chmod +x gitea
sudo mv gitea /usr/local/bin/
4. Prepare Gitea Directories
Create directories for Gitea data, configuration, and logs.
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R git:git /var/lib/gitea/
sudo chmod -R 750 /var/lib/gitea/
sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea
5. Enable Shell Autocompletion (Optional)
Add Gitea autocompletion for zsh or bash.
# For ZSH
cd /usr/share/zsh
sudo wget -O _gitea https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/autocompletion/zsh_autocomplete
# For Bash
sudo wget -O /etc/bash_completion.d/gitea https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/autocompletion/bash_autocomplete
6. Create a systemd Service
Download the sample service file and enable Gitea as a background service.
sudo wget -O /etc/systemd/system/gitea.service https://raw.githubusercontent.com/go-gitea/gitea/release/v1.22/contrib/systemd/gitea.service
# Enable MySQL/MariaDB dependencies in gitea.service
sudo sed -i '/Wants=mysql.service/s/^#//; /After=mysql.service/s/^#//' /etc/systemd/system/gitea.service
sudo sed -i '/Wants=mariadb.service/s/^#//; /After=mariadb.service/s/^#//' /etc/systemd/system/gitea.service
# Start Gitea service
sudo systemctl daemon-reload
sudo systemctl enable gitea
sudo systemctl start gitea
7. Configure MariaDB
Secure and create the database for Gitea.
sudo mysql_secure_installation
sudo mysql -u root -p
CREATE DATABASE gitea CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci';
CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost';
FLUSH PRIVILEGES;
EXIT;
8. Access Gitea
Once started, Gitea runs at http://localhost:3000. Visit that URL on your Pi or network browser to complete setup.
During initial setup, use the following:
- Database Type: MySQL (MariaDB)
- Host: 127.0.0.1:3306
- Database Name: gitea
- Username: gitea
- Password: (the one you set above)
9. (Optional) Make Gitea Public
Point your domain or subdomain to your Raspberry Pi’s IP and use a reverse proxy (e.g. Nginx or Caddy) to serve it on ports 80/443.
TL;DR
Install Git + MariaDB → Create system user → Download Gitea binary → Set directory permissions → Enable service → Configure database → Visit localhost:3000 to finish setup.