Gitea is a lightweight and efficient self-hosted Git service powered by Golang. In this tutorial, we will be installing Gitea on an Ubuntu server.
Before installing Gitea, you need to make sure that your Ubuntu package repository and associated software are updated to the latest version. To do this, run the following commands:
sudo apt update
sudo apt upgrade
Next, you need to install the dependencies required to run Gitea. Gitea requires git, nginx, MariaDB/MySQL, and a few other dependencies. To install them, run the following command:
sudo apt install git nginx certbot mariadb-server mariadb-client
Before we can install Gitea, we need to set up a database for it to use. In this tutorial, we will be using MariaDB.
Start by logging into MariaDB:
sudo mysql -u root
Create a new database and user for Gitea:
CREATE DATABASE gitea;
CREATE USER 'giteauser'@'localhost' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON gitea.* TO 'giteauser'@'localhost';
FLUSH PRIVILEGES;
Replace PASSWORD
with a secure password.
Exit MariaDB:
exit;
Create a new user for Gitea:
sudo adduser --system --shell /bin/bash --gecos 'Gitea Git Repository' --group --disabled-password --home /home/gitea gitea
Download and install Gitea:
sudo su gitea
wget -O gitea https://dl.gitea.io/gitea/1.14.5/gitea-1.14.5-linux-amd64
chmod +x gitea
./gitea web
The above commands download the Gitea binary, give it executable permissions, and start it.
Gitea uses a built-in web server, but it is recommended to use a reverse proxy such as Nginx to improve performance and security.
Create a new Nginx server block:
sudo nano /etc/nginx/sites-available/gitea
Copy and paste the following Nginx configuration to the file:
server {
listen 80;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name _;
ssl_certificate /etc/letsencrypt/live/YOUR_DOMAIN/fullchain.pem; # replace YOUR_DOMAIN
ssl_certificate_key /etc/letsencrypt/live/YOUR_DOMAIN/privkey.pem; # replace YOUR_DOMAIN
location / {
proxy_pass http://localhost:3000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Save and exit the file.
Enable the Nginx server block and test the Nginx configuration:
sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
To protect data transfer between clients and the Gitea server, enable SSL with Certbot.
Run the following command to install Certbot:
sudo apt install certbot python3-certbot-nginx
To obtain and install an SSL certificate, run the following command:
sudo certbot --nginx
Certbot will guide you through the process, and once finished, your Gitea instance should be fully accessible via HTTPS.
You can now access Gitea by navigating to https://domain_name_or_IP/
in a web browser. You will be prompted to create a new account and set up your first repository.
Congratulations! You have successfully installed and set up Gitea on your Ubuntu server.
If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!
Alternatively, for the best virtual desktop, try Shells!