Skip to main content
  1. Posts/

How to install gitea on Debian 11

·403 words·2 mins·
Technology Linux Gitea
Joshua Blais
Joshua Blais
Table of Contents

Here is a quick guide to Install Gitea with Postgresql on Debian 11

Start with a quick system update:

sudo apt-get update -y
sudo apt-get upgrade -y

Setup postgresql

sudo sh -c 'echo "deb $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import repo signing key with:
wget --quiet -O - | sudo apt-key add -

sudo apt-get update
sudo apt-get -y install postgresql

System setup

sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo systemctl status postgresql

Next, You need to switch to ’SCRAM-SHA-256’ scheme from md5 encryption scheme for better security. If you want to connect to PostgreSQL remotely, then you need to allow your IP address in the PostgreSQL configuration file. Open Configuration file to make changes using the following command:

sudo vim /etc/postgresql/15/main/postgresql.conf

# Inside file uncomment:

listen_addresses = 'localhost,'
password_encryption = scram-sha-256

Then, restart systemd service:

sudo systemctl restart postgresql

Login in to postgresql

sudo -u postgres psql

Inside psql:

postgres=# CREATE ROLE gitea WITH LOGIN PASSWORD 'secure@123';

postgres=# CREATE DATABASE giteadb;

postgres=# GRANT ALL PRIVILEGES ON DATABASE giteadb TO gitea;

postgres=# exit

if you receive the error:

The database settings are invalid: migrate: sync: pq: permission denied for schema public

you might have to do the following in psql after the install is complete, I did:


Within /etc/postgresql/15/main/pghba.conf file:

host    giteadb        gitea             scram-sha-256

Install and configure git:

sudo apt install git
git --version

git config --global "Your Name"
git config --global "”
git config --list

Create git user for gitea

sudo adduser \
   --system \
   --shell /bin/bash \
   --gecos 'Git Version Control' \
   --group \
   --disabled-password \
   --home /home/git \

Install gitea:

wget -O /usr/local/bin/gitea
sudo chmod +x /usr/local/bin/gitea

Make directory structure for gitea:

sudo mkdir -p /etc/gitea

sudo mkdir -p /var/lib/gitea/{custom,data,indexers,public,log}

sudo chown -R git:git /var/lib/gitea/

sudo chown root:git /etc/gitea

sudo chmod -R 750 /var/lib/gitea/

sudo chmod 770 /etc/gitea

Create systemd service file:

sudo vim /etc/systemd/system/gitea.service



ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea


sudo systemctl daemon-reload
sudo systemctl start gitea
sudo systemctl enable gitea
sudo systemctl status gitea

# Verify running on port 3000:
netstat -tulpan | grep 3000

Navitate to port 3000 on your server and you will see it running!

Congrats, you have now dropped github as your git server.