Setting Up Gitea on Debian

First install golang. As of the time of this writing, that’s version 1.19.8 in the Debian 12 repos, and since that’s pretty old, we can install a newer version from the upstream developers instead.

Download and install go into /usr/local/go by following the instructions here

Add go to the system path by creating a file in /etc/profile.d/

# /etc/profile.d/go.sh
export PATH=/usr/local/go/bin:$PATH

You can apply this immediately by sourcing /etc/profile now, or log out and back in.

Trying it out on my box:

travis@daedalusgroup:~$ go version
go version go1.24.2 linux/amd64
travis@daedalusgroup:~$ go
Go is a tool for managing Go source code.

Usage:

        go <command> [arguments]

The commands are:

        bug         start a bug report
        build       compile packages and dependencies
        clean       remove object files and cached files
        doc         show documentation for package or symbol
        env         print Go environment information
        fix         update packages to use new APIs
        fmt         gofmt (reformat) package sources
        generate    generate Go files by processing source
        get         add dependencies to current module and install them
        install     compile and install packages and dependencies
        list        list packages or modules
        mod         module maintenance
        work        workspace maintenance
        run         compile and run Go program
        telemetry   manage telemetry data and settings
        test        test packages
        tool        run specified go tool
        version     print Go version
        vet         report likely mistakes in packages

Use "go help <command>" for more information about a command.

Additional help topics:

        buildconstraint build constraints
        buildjson       build -json encoding
        buildmode       build modes
        c               calling between Go and C
        cache           build and test caching
        environment     environment variables
        filetype        file types
        goauth          GOAUTH environment variable
        go.mod          the go.mod file
        gopath          GOPATH environment variable
        goproxy         module proxy protocol
        importpath      import path syntax
        modules         modules, module versions, and more
        module-auth     module authentication using go.sum
        packages        package lists and patterns
        private         configuration for downloading non-public code
        testflag        testing flags
        testfunc        testing functions
        vcs             controlling version control with GOVCS

Use "go help <topic>" for more information about that topic.

travis@daedalusgroup:~$ 

Cool, seems to work! Now on to installing and configuring Gitea

Install and Configure Gitea

We’re going to install the latest released version: 1.23.6 from source by following the instructions here

First it says to make sure GOPATH environment variable is set, so we’ll put that in the go.sh file in /etc/profile.d/, to go alongside the other go related environment changes we’ve made.

# /etc/profile.d/go.sh
export PATH=/usr/local/go/bin:$PATH
export GOPATH=/usr/local/go

Install node.js following these instructions. I’m going to pick version 22, which is an LTS version.

We will also need to install build-essential

sudo apt install build-essential

Now, after installing Node.js, clone the gitea repo and check out the v1.23.6 tag. Then let’s try building it!

git clone https://github.com/go-gitea/gitea
cd gitea
git checkout v1.23.6
TAGS="bindata" make build

And it worked first time! There’s a gitea executable in the working directory, and we should be able to run it. Temporarily open port 3000 on the device since that’s the default port the web interface will listen on (assuming you have a firewall running, right?)

sudo ufw allow 3000
./gitea web

And it was at this point I realized I probably needed to set up a MySQL database first… So let’s do that. Kill the gitea server with Ctrl+C and create the MySQL database and user for gitea

If you don’t have mysql installed yet, it’s as simple as

sudo apt install mariadb
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service

Now add a database for gitea:

sudo mysql
CREATE USER 'gitea'@'%' IDENTIFIED BY 'super-secret-p4ssw0rd';
CREATE DATABASE giteadb CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_bin';
GRANT ALL PRIVILEGES ON giteadb.* TO 'gitea';
FLUSH PRIVILEGES;
quit;

Then restart gitea, fill in your settings, and you’re good to go!

Set up gitea to run as a systemd service

A sample service file comes with the gitea distribution in contrib/systemd/gitea.service. Copy that file to /etc/systemd/system/ and edit it.

In my case, I am running mariadb, so I uncommented Wants=mariadb.service and After=mariadb.service

Also, set user and group to the user and group you want the service to run as. That user has to have an account on the system with a home directory.

Enable and start the service:

sudo systemctl enable gitea.service
sudo systemctl start gitea.service

Congrats on your new self-hosted gitea!

Addenda

I left out some useful web server proxy configurations since they’re unique to my setup, but if anyone is curious and wants to know how to host a public facing instance, reach out and I might add to the instructions here.

But this should get you started for a simple local instance, and if you’re building something public facing, the gitea docs are pretty good. I got my instance up and running quickly by following them.