How to Install Gitea on Ubuntu 24.04 VPS for Self-Hosted Git Hosting
How to Install Gitea on Ubuntu 24.04 VPS for Self-Hosted Git Hosting
Relying on third-party platforms for your source code means accepting their terms, their uptime, and their pricing changes. Running your own Git server puts you back in control, giving you full ownership of your repositories, CI/CD pipelines, and team access policies. Whether you are protecting proprietary code or simply want to cut costs, self-hosting is a smart move for any growing team.
Gitea is one of the best tools available for this job. It is a lightweight, open-source Git service written in Go, which means it runs comfortably on even a modest VPS. It ships with a clean web UI, issue tracking, pull requests, webhooks, and user management right out of the box. In this guide, you will learn exactly how to install Gitea on Ubuntu 24.04 VPS and get it running behind an Nginx reverse proxy with a free SSL certificate.
Gitea vs GitHub vs GitLab Self-Hosted
Before diving into the installation, it helps to understand where Gitea fits among the available options. The table below compares the three most popular choices across key criteria.
| Criteria | Gitea (Self-Hosted) | GitHub (Cloud) | GitLab (Self-Hosted) |
|---|---|---|---|
| RAM Usage | ~150 MB idle | N/A (cloud) | 4 GB+ recommended |
| Ease of Setup | Very easy (single binary) | No setup needed | Complex (many services) |
| Cost | Free + VPS cost | Free tier, then paid | Free + heavy server cost |
| Data Ownership | Full | None | Full |
| Built-in CI/CD | Gitea Actions (optional) | GitHub Actions | GitLab CI (built-in) |
| Minimum VPS Size | 1 vCPU / 1 GB RAM | N/A | 4 vCPU / 8 GB RAM |
Gitea wins on resource efficiency and simplicity, making it the ideal choice for small teams, freelancers, and startups who want professional Git hosting without breaking the bank.
Prerequisites
Before starting, make sure you have the following in place:
- A VPS running Ubuntu 24.04 LTS with at least 1 GB of RAM
- A non-root sudo user
- A domain name (or subdomain) pointed to your server's IP address
- SSH access to the server
- Ports 80 and 443 open in your firewall
If you do not have a server yet, a Ryzen VPS from ByteHosting starts at just €7.99/mo and is provisioned instantly in Frankfurt, Germany. It includes KVM virtualization, full root access, and a 48-hour money-back guarantee.
Step 1 - Update the System and Install Dependencies
Start by updating all existing packages and installing Git, which Gitea relies on internally.
sudo apt update && sudo apt upgrade -y
sudo apt install -y git curl wgetStep 2 - Install and Configure PostgreSQL
Gitea supports SQLite, MySQL, and PostgreSQL. PostgreSQL is the recommended choice for any production setup due to its reliability and performance.
sudo apt install -y postgresql postgresql-contribStart and enable the PostgreSQL service:
sudo systemctl start postgresql
sudo systemctl enable postgresqlNow create a database and user for Gitea:
sudo -u postgres psqlInside the PostgreSQL shell, run the following commands:
CREATE USER gitea WITH PASSWORD 'your_strong_password';
CREATE DATABASE giteadb OWNER gitea ENCODING 'UTF8' LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8' TEMPLATE template0;
\qReplace your_strong_password with a secure password of your choice. Keep it handy for the web installer later.
Step 3 - Create a Dedicated Gitea System User
Running Gitea as root is a security risk. Create a dedicated system user instead:
sudo adduser \
--system \
--shell /bin/bash \
--gecos 'Gitea' \
--group \
--disabled-password \
--home /home/gitea \
giteaCreate the directories Gitea needs and assign the correct ownership:
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R gitea:gitea /var/lib/gitea
sudo chmod -R 750 /var/lib/gitea
sudo mkdir /etc/gitea
sudo chown root:gitea /etc/gitea
sudo chmod 770 /etc/giteaStep 4 - Download the Gitea Binary
Head to the official Gitea download page to find the latest release version. At the time of writing, the latest stable release is 1.22. Adjust the version number in the command below if a newer version is available.
wget -O /tmp/gitea https://dl.gitea.com/gitea/1.22.3/gitea-1.22.3-linux-amd64Move the binary to a system-wide location and make it executable:
sudo mv /tmp/gitea /usr/local/bin/gitea
sudo chmod 755 /usr/local/bin/giteaVerify the installation:
gitea --versionStep 5 - Create a systemd Service for Gitea
Using systemd ensures Gitea starts automatically on reboot and restarts if it crashes.
sudo nano /etc/systemd/system/gitea.servicePaste the following configuration into the file:
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
After=postgresql.service
[Service]
RestartSec=2s
Type=simple
User=gitea
Group=gitea
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=gitea HOME=/home/gitea GITEA_WORK_DIR=/var/lib/gitea
[Install]
WantedBy=multi-user.targetSave the file, then reload systemd and start Gitea:
sudo systemctl daemon-reload
sudo systemctl enable gitea
sudo systemctl start giteaCheck that Gitea is running without errors:
sudo systemctl status giteaBy default, Gitea listens on port 3000. You should see it active in the status output.
Step 6 - Install and Configure Nginx as a Reverse Proxy
Exposing port 3000 directly to the internet is not ideal. Nginx will handle incoming HTTP and HTTPS traffic and forward requests to Gitea internally.
sudo apt install -y nginxCreate a new Nginx server block for your domain:
sudo nano /etc/nginx/sites-available/giteaAdd the following configuration, replacing git.yourdomain.com with your actual domain:
server {
listen 80;
server_name git.yourdomain.com;
location / {
proxy_pass http://127.0.0.1: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;
}
client_max_body_size 512m;
}Enable the site and test the Nginx configuration:
sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginxStep 7 - Secure Gitea with a Free SSL Certificate
Use Certbot with the Let's Encrypt plugin to obtain a free TLS certificate. This step requires your domain DNS to already be pointing at your server's IP.
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d git.yourdomain.comFollow the prompts. Certbot will automatically update your Nginx configuration to redirect HTTP to HTTPS and install the certificate. Renewals happen automatically via a systemd timer.
Your final Nginx configuration will look similar to this after Certbot modifies it:
server {
server_name git.yourdomain.com;
location / {
proxy_pass http://127.0.0.1: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;
}
client_max_body_size 512m;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/git.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/git.yourdomain.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
listen 80;
server_name git.yourdomain.com;
return 301 https://$host$request_uri;
}Step 8 - Configure the Firewall
If you are using UFW, make sure the necessary ports are open:
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw statusStep 9 - Complete the Gitea Web Installer
Open your browser and navigate to https://git.yourdomain.com. You will be greeted by the Gitea installation wizard. Fill in the settings as follows:
Database Settings
- Database Type - PostgreSQL
- Host - 127.0.0.1:5432
- User - gitea
- Password - the password you set earlier
- Database Name - giteadb
General Settings
- Site Title - Your organization name or team name
- Repository Root Path - /home/gitea/repositories (default is fine)
- Git LFS Root Path - /var/lib/gitea/data/lfs
- Run As Username - gitea
- SSH Server Domain - git.yourdomain.com
- Gitea HTTP Listen Port - 3000
- Gitea Base URL - https://git.yourdomain.com
- Log Path - /var/lib/gitea/log
Administrator Account
Scroll to the bottom of the installer page and fill in the optional administrator account section. Create your admin username, email, and password here. If you skip this, the first user to register becomes the admin.
Click Install Gitea and wait a few seconds. You will be redirected to the dashboard. Gitea is now live.
Step 10 - Lock Down the app.ini File
After installation, Gitea writes its configuration to /etc/gitea/app.ini. Tighten the permissions so only the gitea user can read and modify it:
sudo chmod 640 /etc/gitea/app.ini
sudo chown root:gitea /etc/gitea/app.iniOptional - Disable Public Registration
If this is a private server for your team only, disable open registration to prevent unauthorized sign-ups. Edit /etc/gitea/app.ini and find or add the following under the [service] section:
[service]
DISABLE_REGISTRATION = trueThen restart Gitea to apply the change:
sudo systemctl restart giteaKeeping Gitea Updated
Updating Gitea is straightforward since it is a single binary. Download the new release, replace the binary, and restart the service:
sudo systemctl stop gitea
sudo wget -O /usr/local/bin/gitea https://dl.gitea.com/gitea/NEW_VERSION/gitea-NEW_VERSION-linux-amd64
sudo chmod 755 /usr/local/bin/gitea
sudo systemctl start giteaReplace NEW_VERSION with the actual release number. Always check the Gitea changelog for breaking changes before upgrading.
Conclusion
You now have a fully functional, SSL-secured, self-hosted Git server running on Ubuntu 24.04. Gitea gives you a GitHub-like experience at a fraction of the resource cost, and pairing it with a well-specced VPS means you get excellent performance without the overhead of a heavy platform like GitLab.
For the best Gitea experience, consider hosting it on a Ryzen VPS from ByteHosting, starting at just €7.99/mo. With KVM virtualization, NVMe storage, and instant delivery from Frankfurt am Main, Germany, it is a perfect fit for developer workloads. If you are on a tighter budget, the Xeon VPS lineup is another solid option. Browse all affordable VPS plans or grab one of the current limited-time deals to get started today with a 48-hour money-back guarantee.