Introduction
Gitea is a lightweight self-hosted Git service that provides a web interface for managing Git repositories. Setting up Gitea on DigitalOcean can be a great option for developers looking to control their Git workflow without relying on external services. This guide will walk you through the entire process, from provisioning a VPS to installing and configuring Gitea.
Step 1: Provision a DigitalOcean VPS
Before you can install Gitea, you need to provision a virtual private server (VPS) on DigitalOcean. Here is a quick comparison of VPS options suitable for hosting Gitea:
| Provider | Monthly Price | RAM | Storage | CPU |
|---|---|---|---|---|
| Contabo VPS | โฌ5.99 | 4GB | 200GB SSD | 2 vCPU |
| Hetzner Cloud | โฌ4.15 | 2GB | 20GB SSD | 1 vCPU |
| DigitalOcean | $6.00 | 1GB | 25GB SSD | 1 vCPU |
| Vultr | $6.00 | 1GB | 25GB SSD | 1 vCPU |
| Linode | $5.00 | 2GB | 25GB SSD | 1 vCPU |
When choosing a VPS, consider your anticipated usage and select a plan that aligns with your needs. For a basic Gitea setup, the DigitalOcean option at $6/month is a reliable choice.
Provision your VPS by creating an account at DigitalOcean. Once logged in, create a droplet using Ubuntu 20.04 (or the latest LTS version).
Step 2: Setting Up Your VPS
Once your VPS is ready, connect to it via SSH:
ssh root@<your_droplet_ip>
Update Your System
Before installing Gitea, ensure that your system is up to date:
sudo apt update && sudo apt upgrade -y
Install Dependencies
Gitea requires Git, a database server, and some other dependencies. Install them with:
sudo apt install git sqlite3 -y
SQLite is a great lightweight database for small deployments.
Step 3: Install Gitea
Download Gitea
You will need to download the latest Gitea binary. Check the Gitea releases on GitHub for the latest version. Use the command below to download it directly to your server:
wget -O gitea.gz https://dl.gitea.io/gitea/<version>/gitea-<version>-linux-amd64
Extract and move the binary to /usr/local/bin:
sudo tar -xzvf gitea.gz
sudo mv gitea /usr/local/bin/
sudo chmod +x /usr/local/bin/gitea
Create Necessary Directories
Now create directories for Gitea to store files:
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo chown -R root:root /var/lib/gitea/
Create a Gitea User
Create a dedicated user to run Gitea:
sudo adduser --disabled-login --gecos 'Gitea' gitea
Configure Gitea
Create a service file to manage Gitea with systemd:
sudo nano /etc/systemd/system/gitea.service
Add the following content:
[Unit]
Description=Gitea
After=network.target
[Service]
User=gitea
Group=gitea
WorkingDirectory=/var/lib/gitea
ExecStart=/usr/local/bin/gitea web
Restart=always
Environment=USER=gitea HOME=/var/lib/gitea GITEA_WORK_DIR=/var/lib/gitea
[Install]
WantedBy=multi-user.target
Start Gitea
Enable and start the Gitea service:
sudo systemctl enable gitea
sudo systemctl start gitea
Step 4: Configure Gitea via Web Interface
Navigate to http://<your_droplet_ip>:3000 in your browser. You should see the Gitea setup page.
- Database Settings: Choose SQLite for a simple setup.
- Administrator Account: Create an account for managing Gitea.
- Application URL: Set your application URL (e.g.,
http://<your_droplet_ip>:3000).
Once all fields are completed, click the โInstall Giteaโ button to finish the setup.
FAQs
What is Gitea and why should I self-host it?
Gitea is a lightweight, self-hosted Git service offering users a streamlined and customizable interface for managing Git repositories. By self-hosting Gitea, you gain full control over your data, avoid vendor lock-in, and can customize your installation according to your specific needs. This is particularly advantageous for developers and teams valuing privacy and security or those managing their own software development lifecycle.
How much does it cost to host Gitea on DigitalOcean?
Hosting Gitea on DigitalOcean begins at $6 per month for their basic droplet, which provides 1GB RAM, 25GB SSD storage, and 1 vCPU. This configuration is sufficient for small teams or individual projects. However, costs may increase if you require more resources, depending on your projectโs demands. Remember to consider other possible expenses, such as domain registration and backups.
Can I use a different database instead of SQLite for Gitea?
Yes, Gitea supports several databases, including MySQL, PostgreSQL, and MSSQL, in addition to SQLite. While SQLite is suitable for smaller installations, larger deployments or professional environments might benefit from using MySQL or PostgreSQL due to their scalability and performance capabilities. Consult the Gitea documentation for detailed configuration instructions tailored to your chosen database.
Conclusion
Setting up Gitea on DigitalOcean is a straightforward process that can greatly enhance your software development workflow. With this guide, you can now manage your own Git repositories, maintaining full control and customization over your environment. For a broader understanding of VPS options, check out the full VPS comparison.
Take advantage of the self-hosting community by exploring resources on r/selfhosted or contributing to awesome-selfhosted lists. Happy coding!