Raspberry Pi

Wsl - Gitea Git Server Installation

This guide describes, how to install a Git server on WSL. Now the idea is really a bit strange on first consideration: why shouldn't we manage Git in well know repositories, either publicly available or self-hosted? Why should we manage yet another application, data backups etc.?

You need to answer these and similar things yourself. My answers are straightforward as well: because we can. Because we can host artefacts close to our solutions (such as recipes for cookiecutter for example), without really setting up a global view. Because our private repos should be git enabled, but are too brittle to be pushed further ....

If you wish to continue, the below tells you how to do it. At the end of the installation guide, you will get a distro, which (when running) automatically serves yet another git server - in our case Gitea.

A word of warning though: The repositories are stored within the WSL filesystem. So it's a good idea to figure out what happens, if you wipe the distro - how does your backup scheme look like?

Installation

We assume that you have a WSL instance ready (WSL2), with default user set. The guide below was tested on Debian, but it will work for other WSL distros as well, possibly with slight modifications.

  • Make sure that your WSL distro has systemd enabled. As of recent developments, this is as easy as enabling it in the /etc/wsl.conf file within your distro. So the file (together with your default user being configured) may look like this:
[boot]
systemd=true

[user]
default=your-username
  • Install some basic required software
sudo apt install bash-completion # current debian distros are really bare
sudo apt install wget curl
sudo apt install git
  • We have chosen SQLite as the database engine. Install it with the commands below. You can connect or install other dbs - such as PostgreSQL or MariaDB or others, but we are looking for light-weight here.
sudo apt install sqlite3
  • We need to install a gitea user. Let's just copy the recommended setup, as shown below:
sudo adduser \
    --system \
    --shell /bin/bash \
    --gecos 'Git Version Control' \
    --group \
    --disabled-password \
    git
  • Time to download and prepare the latest binary. Go to the Gitea Download Pageand mark down the latest version you wish to get. You will need this string to adjust the download link. We will work with the example version of 1.20
cd ~
# notice the version string is in 2 locations
# sudo wget -O /tmp/gitea https://dl.gitea.io/gitea/{VERSION}/gitea-{VERSION}-linux-amd64
# here below a download of version 1.20
sudo wget -O /tmp/gitea https://dl.gitea.io/gitea/1.20/gitea-1.20-linux-amd64
# move to file to the recommended directory of '/usr/local/bin'
sudo mv /tmp/gitea /usr/local/bin
# make the binary executable
sudo chmod +x /usr/local/bin/gitea
  • create required directories with correct permissions for the git user
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
# notice 770 is too permissive, but needed for the installer to create
# a configuration file. You can set it to less after finishing
sudo chmod 770 /etc/gitea
  • download a systemd unit file and store it in /etc/systemd/system (the file needs no modification, it fits our needs). Be aware that systemd is enabled on your WSL repo - see above.
sudo wget https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/systemd/gitea.service -P /etc/systemd/system/
  • Enable the service and start it
sudo systemctl daemon-reload
sudo systemctl enable --now gitea
# check the staus
sudo systemctl status gitea

Installation is done. Time to configure the system.

Gitea configuration

Gitea is installed and running. Let us do a one page setup and start using the system.

  • Launch gitea. By default, it is listening on port 3000. Type the below URL into your browser.
http://localhost:3000
  • A configuration screen appeared. We only need choose the database settings:
    • On Database Type, select SQLite3
    • It is of course a good idea to setup the other parameters: site name etc., but the rest will work without modification as well
  • Press the Install Button
  • The final step is to create your admin account. Click on the Need an account? Register now link. The first registered user is automatically added to the Admin group.

Cleanup

During installation, we have set the gitea directory to high permissions. It's time to change the permissions, and make our config file read only.

sudo chmod 750 /etc/gitea
sudo chmod 640 /etc/gitea/app.ini

Our WSL articles: