Gitea is a lightweight, self-hosted Git service that allows you to manage repositories with ease. In this guide, we will walk you through the installation of Gitea on Ubuntu 22.04. Whether you are deploying it on a local server or using a Windows VPS UK, this tutorial covers all the necessary steps.
Step 1: Update Your System
Before installing Gitea, ensure your system is up to date. Run the following commands:
sudo apt update && sudo apt upgrade -y
Keeping your system updated is crucial for security and performance, whether you're setting it up locally or on a VPS Windows Servers platform.
Step 2: Install Required Dependencies
Install the necessary dependencies for Gitea:
sudo apt install -y git mariadb-server
Step 3: Configure MariaDB
Start the MariaDB service and secure it:
sudo systemctl start mariadb
sudo mysql_secure_installation
Log in to the MariaDB console:
sudo mysql -u root -p
Create a new database and user for Gitea:
CREATE DATABASE gitea;
CREATE USER 'giteauser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON gitea.* TO 'giteauser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace your_password
with a strong password of your choice.
Step 4: Download Gitea
Create a directory for Gitea and download the latest release:
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R $(whoami):$(whoami) /var/lib/gitea
cd /tmp
wget https://dl.gitea.io/gitea/latest/gitea-latest-linux-amd64
sudo mv gitea-latest-linux-amd64 /usr/local/bin/gitea
sudo chmod +x /usr/local/bin/gitea
Step 5: Create a Gitea Service
Create a systemd service file for Gitea:
sudo nano /etc/systemd/system/gitea.service
Add the following content to the file:
[Unit]
Description=Gitea
After=network.target
[Service]
User=your_username
Group=your_username
WorkingDirectory=/var/lib/gitea
ExecStart=/usr/local/bin/gitea web
Restart=always
Environment=USER=your_username
Environment=HOME=/var/lib/gitea
[Install]
WantedBy=multi-user.target
Replace your_username
with your actual username. Save and exit the file.
Step 6: Start Gitea
Enable and start the Gitea service:
sudo systemctl enable gitea
sudo systemctl start gitea
Step 7: Configure Nginx as a Reverse Proxy (Optional)
If you want to run Gitea behind Nginx, first install Nginx:
sudo apt install nginx -y
Create a new Nginx configuration file for Gitea:
sudo nano /etc/nginx/sites-available/gitea
Add the following configuration, replacing your_domain.com
with your actual domain:
server {
listen 80;
server_name your_domain.com;
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, then create a symlink to enable the configuration:
sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
Test the Nginx configuration for syntax errors:
sudo nginx -t
If everything is okay, restart Nginx:
sudo systemctl restart nginx
Step 8: Access Gitea
Open your web browser and navigate to:
http://your_domain.com
You should see the Gitea setup page. Follow the instructions to complete the installation.