Skip to content

How to install gitea git server on Ubuntu 18

# download gitea binary
wget -O gitea1.9.3.xz https://github.com/go-gitea/gitea/releases/download/v1.9.3/gitea-1.9.3-linux-amd64.xz

# extract archive
unxz gitea1.9.3.xz

# check binary integrity
cat https://github.com/go-gitea/gitea/releases/download/v1.9.3/gitea-1.9.3-linux-amd64.sha256
sha256sum gitea1.9.3

# make binary executable
chmod +x gitea1.9.3

# move gitea binary to final location
mv gitea1.9.3 /usr/local/bin/

# create symbolic link to current version
ln -s /usr/local/bin/gitea1.9.3 /usr/local/bin/gitea

# create system user to run gitea
adduser \
--system \
--shell /bin/bash \
--gecos 'Gitea' \
--group \
--disabled-password \
--home /home/gitea \
gitea

# create directories and permissions
mkdir -p /var/lib/gitea/{custom,data,log}
chown -R gitea:gitea /var/lib/gitea/
chmod -R 750 /var/lib/gitea/
mkdir /etc/gitea
chown root:gitea /etc/gitea
chmod 770 /etc/gitea

# create gitea service
# https://github.com/go-gitea/gitea/blob/master/contrib/systemd/gitea.service
nano /etc/systemd/system/gitea.service

[Unit]
Description=Gitea
After=syslog.target
After=network.target
#Requires=mysql.service
Requires=mariadb.service
#Requires=postgresql.service
#Requires=memcached.service
#Requires=redis.service

[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
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
RestartSec=2s
Type=simple
User=gitea
Group=gitea
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=gitea HOME=/home/gitea GITEA_WORK_DIR=/var/lib/gitea
# If you want to bind Gitea to a port below 1024 uncomment
# the two values below
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

# enable and start service
systemctl enable gitea
systemctl start gitea

# create database and user
mysql -u root

CREATE DATABASE gitea;

CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'password';

GRANT SELECT, INSERT, UPDATE, DELETE, DROP, INDEX, ALTER, CREATE, CREATE TEMPORARY TABLES, CREATE VIEW, EVENT, TRIGGER, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON `gitea`.* TO 'gitea'@'localhost';
FLUSH PRIVILEGES;

# create SSH tunnel between server and local machine for port 3000
ssh user@octopuslabs.io -i private.pem -L 3000:localhost:3000 -N -v

# install gitea through browser
http://localhost:3000/install

# create the first user account which will be the main admin
http://localhost:3000/register

# once installation is complete, update permissions
chmod 750 /etc/gitea
chmod 640 /etc/gitea/app.ini

# to use gitea without SSH tunnel and on default port 80, we setup gitea running through apache reverse proxy
# add to apache site https config

...


Order allow,deny
Allow from all

AllowEncodedSlashes NoDecode

# Note: no trailing slash after either /git or port
ProxyPass /gitea http://localhost:3000 nocanon
ProxyPassReverse /gitea http://localhost:3000

# enable apache proxy module
a2enmod proxy_http

# restart apache
systemctl restart apache2

# edit gitea config
[server]
ROOT_URL = https://octopuslabs.io/gitea/

# restart gitea service
systemctl restart gitea

# test in browser
https://octopuslabs.io/gitea/

# enable git lfs support
LFS_START_SERVER = true
LFS_CONTENT_PATH = /home/gitea/data/lfs

# hide gitea from search engine
You may want to hide your gitea installation from search engines...

# tweak gitea configuration
https://github.com/go-gitea/gitea/blob/master/custom/conf/app.ini.sample