Step-by-Step Guide to Installing and Configuring Gitea as a Self-Hosting Git Repository on Ubuntu 24.04
Introduction
If you're looking to host your own Git repositories securely and efficiently, install Gitea on Ubuntu 24.04 is an excellent choice. Gitea is a lightweight, self-hosted Git service that offers a user-friendly interface, robust features, and easy management. At ByteHosting, we understand the importance of reliable hosting, and in this guide, we'll walk you through the step-by-step process of installing and configuring Gitea on your Ubuntu 24.04 server, ensuring optimal security and performance.
Prerequisites: VPS Setup, Domain, and SSL Considerations
Before diving into the installation, ensure you have a VPS ready. We recommend our cost-effective KVM VPS plans, which provide the performance and stability needed for hosting Git repositories. You should also have a registered domain pointing to your server's IP address. For secure access, setting up SSL is crucial—either via Let's Encrypt or your preferred certificate authority—to encrypt data in transit.
Here's a quick checklist:
- VPS with Ubuntu 24.04 installed
- Domain pointing to your server's IP
- Root or sudo privileges on the server
- Basic knowledge of Linux command line
Download Gitea Binary and Prepare System Dependencies
First, connect to your server via SSH. Then, update your package list and install necessary dependencies:
sudo apt update
sudo apt install -y git sqlite3 wget ca-certificates
Next, download the latest Gitea binary. Visit the official Gitea downloads page to find the latest version. For example:
GITEA_VERSION=1.20.4
wget -O gitea https://dl.gitea.io/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64
Make the binary executable and move it to /usr/local/bin for system-wide access:
chmod +x gitea
sudo mv gitea /usr/local/bin/
Install Gitea as a systemd Service for Automatic Management
To ensure Gitea runs smoothly and restarts automatically, set it up as a systemd service. First, create a dedicated user:
sudo adduser --system --group --disabled-login --no-create-home giteaThen, create necessary directories:
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R gitea:gitea /var/lib/gitea
sudo chmod -R 750 /var/lib/giteaNext, create a systemd service file:
sudo nano /etc/systemd/system/gitea.serviceInsert the following configuration:
[Unit]
Description=Gitea
After=network.target
[Service]
User=gitea
Group=gitea
Type=simple
ExecStart=/usr/local/bin/gitea web -p 3000 --config /etc/gitea/app.ini
Restart=always
Environment=USER=gitea HOME=/home/gitea
[Install]
WantedBy=multi-user.targetSave and enable the service:
sudo systemctl daemon-reload
sudo systemctl enable gitea
sudo systemctl start giteaYou can check the status with:
sudo systemctl status giteaConfigure Gitea Settings for Secure Access and Repository Management
Once Gitea is running, access it via your server's IP or domain on port 3000:
Follow the initial setup wizard to configure your database, application URL, and administrator account. For production, it's recommended to set up SSL. You can do this by configuring a reverse proxy with Nginx or Apache, terminating SSL there.
Sample Nginx Reverse Proxy with SSL
server {
listen 443 ssl;
server_name your-domain.com;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;
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;
}
}
This setup ensures your Gitea interface is accessible securely over HTTPS.
Verify Gitea Installation and Initial Login
After completing the setup, log in with the administrator account you created. Verify that repositories can be created, cloned, and managed. Test access over HTTPS to confirm SSL is working correctly.
Troubleshoot Common Issues
Service Startup Problems
If Gitea doesn't start, check the service status:
sudo systemctl status giteaReview logs for errors and ensure the binary has correct permissions.
Permissions and Ownership
Ensure all directories and files are owned by the gitea user, especially /var/lib/gitea.
SSL and Reverse Proxy Issues
If SSL isn't working, double-check your certificate paths and proxy configuration. Use tools like curl -I https://your-domain.com to verify HTTPS response headers.
Conclusion
Self-hosting Gitea on Ubuntu 24.04 provides a secure, efficient way to manage your Git repositories privately. By following our step-by-step guide, you can set up Gitea with optimal security and performance. At ByteHosting, we’re committed to providing reliable hosting solutions, and our VPS plans are perfect for hosting your own Gitea instance. Whether you're an individual developer or a team, hosting your own Git service empowers you with full control over your code. Get started today and enjoy seamless, self-managed Git repositories!