Gitea is a lightweight, self-hosted Git service that allows developers to manage their Git repositories with ease. It provides a web interface similar to GitHub, Bitbucket, and GitLab, making it an excellent option for setting up your own Git hosting service. In this guide, we’ll walk you through the steps to install and configure Gitea on a VPS for hosting your Git repositories.
Prerequisites
Before you start, ensure the following:
- A VPS running Ubuntu 20.04 or any other supported Linux distribution.
- Root or sudo privileges to install software and configure system settings.
- A domain name or public IP address to access your Gitea server remotely.
- A firewall (optional) to restrict access and secure your VPS.
Step 1: Update Your VPS
Start by updating your VPS to make sure all system packages are up to date. This ensures that you're using the latest, secure versions of your packages.
Step 2: Install Dependencies
Gitea has some dependencies, including git
, sqlite3
(for local database storage), and curl
. Install them by running the following commands:
Step 3: Create a Gitea User
For security purposes, it’s a good practice to create a separate user to run Gitea instead of using the root user. Create the gitea
user and assign it appropriate permissions.
Step 4: Install Gitea
Gitea provides precompiled binaries for easy installation. To install it, you can download the binary from the official Gitea releases page.
-
Download the Gitea binary:
Visit the official Gitea GitHub releases page to find the latest stable release:
https://github.com/go-gitea/gitea/releasesYou can download it using
wget
:Replace
<version>
with the actual version number you want to install. -
Move the Gitea binary to the appropriate location:
After downloading the binary, move it to
/usr/local/bin/
: -
Make the binary executable:
Step 5: Configure Gitea as a Service
To ensure that Gitea starts automatically on boot and runs as a background service, you can create a systemd service.
-
Create a systemd service file:
-
Add the following content to the file:
-
Reload the systemd service manager to apply the changes:
-
Enable Gitea to start on boot:
-
Start the Gitea service:
Step 6: Open Ports in the Firewall (Optional)
If you have a firewall enabled on your VPS, you need to allow HTTP and HTTPS traffic to access Gitea.
-
Allow HTTP (port 3000) and HTTPS (port 443) traffic if you're using a firewall like UFW:
-
Enable UFW if it is not already enabled:
-
Check UFW status to confirm the rules are applied:
Step 7: Access Gitea Web Interface
Once the Gitea service is up and running, you can access it through a web browser by navigating to your VPS's IP address or domain name, followed by port 3000
. For example:
Or, if you have a domain configured:
Step 8: Complete the Web Installer
The first time you access Gitea, you'll be prompted to complete the initial configuration through the web interface.
-
Choose the database type. For simplicity, you can use the default
SQLite3
database. -
Set the server URL to your VPS's IP address or domain name:
- Application URL:
http://your_vps_ip:3000
(or your domain name). - Repository Root Path:
/home/gitea/gitea-repositories
(default path for repository storage).
- Application URL:
-
Create an admin account by entering your desired username, password, and email address.
-
Click "Install Gitea" to complete the installation process.
Step 9: Access Your Gitea Dashboard
Once the installation is complete, you can log in to the Gitea web interface using the admin credentials you just created. From there, you can start creating and managing Git repositories, as well as configuring settings for users, teams, and more.
Step 10: Set Up SSL for Secure Access (Optional)
To ensure secure connections, it’s highly recommended to configure SSL (HTTPS) for your Gitea server. You can use Let’s Encrypt for a free SSL certificate.
-
Install Certbot for obtaining and managing SSL certificates:
-
Request an SSL certificate for your domain:
Follow the prompts to complete the SSL setup.
-
Test the SSL setup by visiting
https://your_domain.com
in your browser.
Step 11: Configure Backups (Optional)
It's essential to back up your Gitea server to avoid data loss. You can create regular backups of the repository database and configuration files.
-
Backup Gitea repositories:
Use the following command to back up Gitea repositories:
-
Backup Gitea configuration:
Back up the configuration file, which is located at
/home/gitea/.gitea
.
Conclusion
You have successfully installed and configured Gitea on your VPS for Git hosting. With Gitea, you now have a self-hosted Git service that you can use for managing repositories and collaborating with your team. Remember to secure your Gitea server with SSL and consider setting up regular backups to protect your data.
Feel free to explore more advanced features of Gitea, such as integrating webhooks, managing multiple repositories, and configuring LDAP authentication for enterprise environments.