Jump to content ↓
Software Developer in London, UK.

Setting up Gitea on Ubuntu 18.04 - 2018/10/07

A fleshed out version of the Gitea install guide based on my experience of setting up Gitea from scratch on Ubuntu 18.04.

If you’re looking to run and host this remotely, I recommend giving Digital Ocean if you don’t yet have anywhere in mind, here’s a referral link giving you 10$ free credit if you fancy giving them a try.

What is Gitea

From the original announcement post

Gitea is a community fork of the popular self-hosted Git service Gogs.

I’ve previously used Gogs for self hosting some git repositories, but have been keen to try Gitea, especially since I’ve seen there is a dark theme option in the pipeline.


Run the following as root:

Create git user for Gitea

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

Create required directory structure

mkdir -p /var/lib/gitea/{custom,data,indexers,public,log}
chown git:git /var/lib/gitea/{data,indexers,log}
chmod 750 /var/lib/gitea/{data,indexers,log}
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 770 /etc/gitea

Download binary

wget -O gitea https://dl.gitea.io/gitea/1.5.0/gitea-1.5.0-linux-amd64

Move binary to global location, set permissions and make executable

mv gitea /usr/local/bin/gitea
chown -R root:git /usr/local/bin/gitea
chmod +x /usr/local/bin/gitea

Run Gitea

gitea web

Single shell script of all install steps

All of the above condensed into one block for easy copy and pasting

adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git
mkdir -p /var/lib/gitea/{custom,data,indexers,public,log}
chown git:git /var/lib/gitea/{data,indexers,log}
chmod 750 /var/lib/gitea/{data,indexers,log}
mkdir /etc/gitea
chown root:git /etc/gitea
chmod 770 /etc/gitea
wget -O gitea https://dl.gitea.io/gitea/1.5.0/gitea-1.5.0-linux-amd64
mv gitea /usr/local/bin/gitea
chown -R root:git /usr/local/bin/gitea
chmod +x /usr/local/bin/gitea
gitea web


By default the Gitea web interface runs on port 3000: (switch out if needed with server IP/hostname)

Visit and you should be presented with the landing page.

Gitea isn’t quite ready to use as there is an install step that Gitea will present to you as soon as you attempt to navigate anywhere in the web interface (e.g. via the Register link).

From here you specify a few configuration values, such as database credentials, and you can elect to create an admin user at the bottom of the form. If an admin user is not created, the first user to register on Gitea will be given admin privileges.

And that’s pretty much it, you’re good to go. There’s an admin section where you can see the status and configuration values. To edit the configuration you need to edit the app.ini file (nano /etc/gitea/app.ini) and stop and start Gitea for the change to take affect.

1st optional step: run Gitea automatically via supervisor

To keep Gitea running outside of the active terminal session (back when we ran gitea web), we can use Supervisor: A Process Control System

Note that there are many options for managing and persisting processes in the background, Supervisor is the one I’m most familiar/comfortable with.

Install supervisor:

apt update -y
apt install supervisor -y

Create the supervisor config for Gitea:

echo "\
command=/usr/local/bin/gitea web -c /etc/gitea/app.ini
user = git
group = git
environment = HOME="/home/git", USER="git", GITEA_WORK_DIR="/var/lib/gitea"
" > /etc/supervisor/conf.d/gitea.conf

Run the following to have supervisor pick up the new config and start the process for Gitea:

supervisorctl reread
supervisorctl update

Gitea should now be running as before on port 3000. You can stop or start Gitea with supervisorctl stop gitea and supervisorctl start gitea.

2nd optional step: serve Gitea web interface via nginx

Accessing the web interface via port 3000 might not be desirable. Gitea does allow us to configure the port (and host, SSL, etc), however I prefer to use nginx to proxy through and serve from the original port.

Install nginx:

apt install nginx -y

Create nginx configuration for Gitea (update domain as needed)

echo "\
server {
    listen 80;
    server_name gitea.example.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        proxy_read_timeout          600;
        send_timeout                600;
" > /etc/nginx/sites-available/gitea

Enable the configuration, use nginx -t before hand to test the config for obvious errors:

ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
nginx -s reload

The Gitea documentation does also have a page on configuring reverse proxies, with a few examples of configuring other software to serve Gitea (Apache, Caddy) and an example of serving Gitea from outside the root of a domain (e.g. http://example.com/gitea/).

Using MySQL

I originally planned on using the SQLite option with Gitea, since I’m setting it up for primary personal use on a remote machine, however a current open issue on the project made me decide it was worth the minimal effort to run it on MySQL. The assumption is this MySQL server is already installed (e.g. apt install mysql-server) and configured with a database and user for use with Gitea, example snippet on creating a MySQL DB and user:

CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'setAPassword';
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost';