Gitea is a versatile open-source forge software package that provides a robust platform for hosting software development version control using Git. It also offers a range of collaborative features such as bug tracking, wikis, and code review. In this comprehensive guide, we will walk you through the step-by-step process of installing Gitea on your Ubuntu 23.10 server.
Prerequisites
Before we begin, make sure you have full SSH root access or a user with Sudo privileges. Additionally, Gitea supports several databases, including SQLite, PostgreSQL, MySQL, and MariaDB. For this guide, we will be using SQLite as the database for Gitea. However, feel free to choose any of the supported databases based on your specific requirements.
To install SQLite, use the following command:
apt install sqlite3
To verify the installation and check the version, run the following command:
sqlite3 --version
Installing Git
Gitea is a self-hosted Git service that provides features similar to popular platforms like GitHub, Bitbucket, or GitLab. To install Git on your Ubuntu system, follow these steps:
- First, check for system updates and install them:
apt update apt upgrade
- Install the Git package using the following command:
apt install git
- To verify the installation and check the version of Git, run the following command:
git --version
Creating a Git User
To ensure secure and controlled access to Gitea, we will create a dedicated Git user with limited privileges. Follow the steps below to create the Git user:
adduser --system --shell/bin/bash --gecos 'Git Version Control' --group --disabled-password --home/home/git git
Downloading the Gitea Binary
To download the Gitea binary, follow these steps:
- Use the following command to download the Gitea binary:
wget -O /tmp/gitea https://dl.gitea.com/gitea/1.21/gitea-1.21-linux-amd64
- Move the downloaded Gitea binary file to the
/usr/local/bin
directory:
mv /tmp/gitea /usr/local/bin
- Make the binary executable:
chmod +x /usr/local/bin/gitea
Creating the Directory Structure
Next, we need to create the necessary directory structure for Gitea and set the required permissions and ownership. Follow these steps:
mkdir -p /var/lib/gitea/{custom,data,indexers,public,log} chown git: /var/lib/gitea/{data,indexers,log} chmod 750 /var/lib/gitea/{data,indexers,log} mkdir /etc/gitea chown root:git /etc/gitea chmod 770 /etc/gitea
Creating a Systemd Unit File
To run Gitea in the background and have control over it using systemctl
, we need to create a Systemd Unit File. Follow these steps:
- Download the Unit File to the
/etc/systemd/system/
directory:
wget https://raw.githubusercontent.com/go-gitea/gitea/main/contrib/systemd/gitea.service -P /etc/systemd/system/
- Reload the Systemd daemon to load the new Unit File:
systemctl daemon-reload
- Enable the Gitea service to start on boot:
systemctl enable gitea
Configuring Gitea
Now that we have completed the initial setup, it’s time to configure Gitea. Follow the steps below:
- If you are running the ufw firewall on your server, allow port 3000:
ufw allow 3000/tcp
- Open your web browser and navigate to
http://yourserver-ip-address:3000
to access the Gitea dashboard. - Follow the on-screen instructions to complete the Gitea setup, providing the following information:
- Database Settings:
- Database Type: SQLite3
- Path: Use an absolute path, such as
/var/lib/gitea/data/gitea.db
- Application General Settings:
- Site Title: Enter your preferred site name here
- Repository Root Path: Keep the default value
/home/git/gitea-repositories
- Git LFS Root Path: Keep the default value
/var/lib/gitea/data/lfs
- Run As Username:
git
(the Git user created earlier) - Server Domain: Enter your domain name or the IP address of the server
- SSH Port: 22 (change it if SSH is listening on a different port)
- Gitea HTTP Listen Port: 3000
- Gitea Base URL: Use
http
with your domain name or server IP address (e.g.,http://example.com:3000
orhttp://192.168.0.2:3000
) - Log Path: Leave it as the default value
/var/lib/gitea/log
- Replace instances of
localhost
with either your server’s IP address or your domain name. - Optional Settings:
- Create an Administrator user account.
- Click on the “Install” button to Install and Configure Gitea.
Once the installation is complete, you will be logged in as the Administrator and redirected to the Gitea dashboard. Now, you can start creating your first Gitea Repository with ease.
Upgrading Gitea
To upgrade Gitea to a newer version, follow these steps:
- Stop the Gitea service:
systemctl stop gitea
- Download the latest Gitea binary from the official download page. Replace
<THE_LATEST_GITEA_VERSION>
with the version you want to install:
VERSION=<THE_LATEST_GITEA_VERSION> wget -O /tmp/gitea https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-linux-amd64
- Move the downloaded Gitea binary file to
/usr/local/bin
and make it executable:
mv /tmp/gitea /usr/local/bin chmod +x /usr/local/bin/gitea
- Restart the Gitea service to apply the changes:
systemctl restart gitea
Congratulations! You have successfully installed and configured Gitea on your Ubuntu 23.10 server. You can now enjoy the powerful features of Gitea and streamline your software development process.
For reliable and scalable cloud hosting solutions, consider Shape.host’s Cloud VPS services. Shape.host provides efficient and secure cloud hosting solutions, empowering businesses to thrive in a digital world.