How to Install Gitea on Ubuntu Server Latest

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.

Prerequisites

Step 1: Updating Ubuntu Packages

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

Step 2: Install Dependencies

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

Step 3: Configure the Database

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;

Step 4: Download and Configure Gitea

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.

Step 5: Set Up Reverse Proxy with Nginx

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

Step 6: Enable SSL with Certbot

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.

Step 7: Access Gitea

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!