Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Installing Gitea on Raspberry Pi 3 b+ with nginx and automatic backups

Setup Gitea on Raspberry Pi (3b+)

These instructions are based on this article:

Other instructions.

Setup Raspberry Pi with minimal Raspbian image. You need to connect to the HDMI port and set the following:

Use Noobs to install Raspian.

Open menu Preferences > Raspberry Pi Settings

There you need to enable the SSH server and you should change the hostname.

Then configure the correct timezone:

Now log in via ssh and execute the following commands:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install zip git -y

Install nginx

# Might need to update sources.list if nginx package isn't found.
sudo pico /etc/apt/sources.list
# uncomment last line
sudo apt-get update

sudo apt-get install nginx -y

Create a new user:

sudo adduser --disabled-login --gecos 'Gitea' git

Install latest release of Go

git clone
cd update-golang
sudo ./

Updating version of Go

From the pi user issue the following command. sudo ./

Then you will need to rebuild Gitea to use the updated version of Go.

Change to user git:

sudo su - git

Set environment variables

You will eventually need to add these environmental variables to each user pi, git, root

export PATH=$PATH:/usr/local/go/bin
export GOPATH=/home/git
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOPATH/src/
export PATH=$PATH:$GOPATH/src/

Download go-bindata

go get

Download the latest gitea version:

go get -d -u

Now type exit to go back to pi user

Build it under root user

sudo su - root

Reset environment variables above with root user

cd $GOPATH/src/
TAGS="bindata sqlite" make generate build

Now type exit to go back to pi user.

Configure Gitea and Nginx

Create/Edit /etc/systemd/system/gitea.service and add the following content:

After=mariadb.service mysqld.service postgresql.service memcached.service redis.service

# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
ExecStart=/home/git/src/ web
Environment=USER=git HOME=/home/git

# Start gitea:
sudo systemctl enable gitea
sudo systemctl start gitea

Create/Edit /etc/nginx/sites-available/gitea and insert the following:

server {
    listen 80;
    server_name gitea;
    location / {
        client_max_body_size 364M;
        proxy_pass http://localhost:3000;
        proxy_connect_timeout 600;
        proxy_send_timeout 600;
        proxy_read_timeout 600;
        send_timeout 600;
        proxy_set_header X-Real-IP $remote_addr;

Then enable the gitea nginx-site and restart the nginx server:

sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/gitea
sudo service nginx restart

Update Gitea

sudo su - git

# Load environmental variables to $PATH as above

cd $GOPATH/src/
git checkout <branch>
go get -d -u
sudo su - root

# Load environmental variables to $PATH as above

cd $GOPATH/src/
TAGS="bindata sqlite" make generate build
sudo systemctl restart gitea

Create backup-script

Now we want to create a backup script that is run by crontab every day. To do so, create a new file called and insert the following content (replace YOUR_SERVER/YOUR/DIR as well as USER and PASSWORD):


# Create directory if it does not exist
mkdir -p git

# Mount NAS directory
sudo mount -t cifs //<your-nas>/Git git -o user=<your-nas-user>,pass=<your-password>

# Create backup directory if it does not exist and cd into it
mkdir -p git/gitea-backups

# Run the backup job
sudo zip -r "git/gitea-backups/gitea-backup-$(date +"%Y-%m-%d %H-%M-%S").zip" /home/git/src/ /home/git/src/ /home/git/gitea-repositories

# Remove all files, keeping the last recent one and cd back
cd git/gitea-backups
ls -t1 . | tail -n +3 | xargs -d '\n' rm -f
cd ../..

# Allow changing the backup dir and files
sudo chmod -R 777 git/gitea-backups

# Clean up everything
sudo umount git
rmdir git

Now chmod +x and create a new crontab entry:

crontab -e

# Now add the following line:
0 0 * * * /home/pi/

This calls our script everyday at 0:00 AM, creates a gogs dump and copies it to our network share.

Virtual memory exhausted: Cannot allocate memory

sudo nano /etc/dphys-swapfile

Default value in Raspbian is: CONF_SWAPSIZE=100

Change to: CONF_SWAPSIZE=1024

Restart swapfile service

sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start

Check memory+swap free -m

You should probably switch the swapsize back once the installation is complete to avoid potential disk issues.

You should find your instance of Gitea at http://localhost:3000, where localhost is the LAN IP of your Raspberry Pi. On your Raspberry Pi you should find it at http://gitea:3000


This comment has been minimized.

Copy link

FireBlaim commented Apr 27, 2019

Thanks !! It works !


This comment has been minimized.

Copy link

lituss commented May 21, 2019

it works , i needed to increase swap file to compile.
the binaries does't work for my raspberry.
Thank you!!!


This comment has been minimized.

Copy link

DanieBeets commented Oct 12, 2019

Thanks for this!


This comment has been minimized.

Copy link

Natendrtfm commented Dec 21, 2019

I need help !
I did everything and had no error but i don't know if it worked (localhost and the ip leads to nginx default message) so where to find gitea once installed ?


This comment has been minimized.

Copy link
Owner Author

afragen commented Dec 21, 2019

@Natendrtfm since it's running on your LAN, look at your router and find the local IP address. It should be running on port 3000.

So the address would be something like, essentially the http://localhost:3000 for your Raspberry Pi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.