Skip to content

Install Gitea

Prerequisites

Git

  1. Install Git
sudo apt install git

MariaDB

  1. Install MariaDB
sudo apt install mariadb-server mariadb-client
  1. Configure MariaDB
sudo mysql_secure_installation

A few questions will be asked, including setting a root password. This is the password for MariaDB, and is not the root password of the PC.

Enter current password for root (enter for none): Just press the Enter
Set root password? [Y/n]: Y
New password: Enter password
Re-enter new password: Repeat password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]:  Y
Reload privilege tables now? [Y/n]:  Y
  1. Restart MariaDB
sudo systemctl restart mariadb.service
  1. Log into MariaDB
sudo mysql -u root -p
  1. Create database called gitea
CREATE DATABASE giteadb;
  1. Create a database user called giteauser. Give it a password which Gitea will use to log into the database.
CREATE USER 'giteauser'@'localhost' IDENTIFIED BY 'new_password_here';
  1. Now grant the user full access to the database
GRANT ALL ON gitea.* TO 'giteauser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
  1. Now save your changes and exit
FLUSH PRIVILEGES;
EXIT;

Prepare environment

  1. Add user git
sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' --group --disabled-password --home /home/git git
  1. Create the needed directory structure
sudo mkdir -p /var/lib/gitea/{custom,data,indexers,public,log}
sudo chown git:git /var/lib/gitea/{data,indexers,log}
sudo chmod 750 /var/lib/gitea/{data,indexers,log}
sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

Install Gitea

Download Gitea

  1. Download Gitea executable
sudo wget -O gitea https://dl.gitea.io/gitea/1.5.0/gitea-1.5.0-linux-amd64
  1. Set it to executable
sudo chmod +x gitea
  1. Copy the binary to a global location
sudo cp gitea /usr/local/bin/gitea

Create service file

Now we create a service file to start and restart automatically. 1. Create a linux service

sudo nano /etc/systemd/system/gitea.service
  1. Fill the file with this:
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
#After=mysqld.service
#After=postgresql.service
#After=memcached.service
#After=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=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git 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
  1. Enable Gitea service
sudo systemctl daemon-reload
sudo systemctl enable gitea
sudo systemctl start gitea
  1. Check the status of the gitea service
sudo systemctl status gitea

● gitea.service - Gitea (Git with a cup of tea)
  Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: en
  Active: active (running) since Wed 2018-10-10 14:15:28 CDT; 19ms ago
 Main PID: 17769 (gitea)
   Tasks: 4 (limit: 2321)
  CGroup: /system.slice/gitea.service
       ├─17769 /usr/local/bin/gitea web -c /etc/gitea/app.ini
       └─17774 /usr/local/bin/gitea web -c /etc/gitea/app.ini
  1. Go through the web installer

    Open 127.0.0.1:3000/installer, or connect to the web interface via ip-address:3000/installer, where ip-address is the ip address of the computer running Gitea. 6. Enjoy your own Gitea instance!


Additional Info:

You can see all Gitea downloads here: https://dl.gitea.io/gitea A reference i used for this tutorial: https://www.vultr.com/docs/how-to-install-gitea-on-ubuntu-18-04