openSUSE

How To Install Gitea on openSUSE

Install Gitea on openSUSE

In this tutorial, we will show you how to install Gitea on openSUSE. Gitea is a lightweight, self-hosted Git service that provides a convenient way to manage and collaborate on software development projects. Its streamlined interface and minimal system footprint make it an ideal choice for teams or individuals who want an efficient platform without the overhead of larger hosting solutions. Combining Gitea’s agility with the stability and versatility of openSUSE can help optimize code version control operations while ensuring a secure and robust environment.

This article provides a detailed, step-by-step guide on installing Gitea on openSUSE. The instructions focus on both simplicity and reliability, ensuring you can deploy this platform with minimal effort. It covers prerequisites, how to set up a dedicated Gitea user, installation methods (using official repositories or manual installation), database configuration, and best practices for running Gitea as a service. It also delves into security, troubleshooting tips, and post-installation tasks, giving you a complete overview for a successful installation. By following the sections below, you will learn all essential aspects of running Gitea on your openSUSE system, from initial setup to advanced maintenance and security enhancements.

Prerequisites

Before installing Gitea on openSUSE, ensure you have the following prerequisites in place:

  1. System Requirements: Gitea’s resource footprint is small, but having at least 1GB of RAM and 2GB of disk space is a good starting point. This requirement may vary slightly if your repository hosting and collaboration needs grow significantly. Make sure to have enough storage for potential repository expansions and backups.
  2. Operating System: An updated openSUSE system is recommended. Using openSUSE Leap 15.x or Tumbleweed ensures you gain the latest compatibility updates. Update your system packages to reduce potential conflicts:
    sudo zypper refresh
    sudo zypper update
    
  3. Root or Sudo Privileges: The installation requires administrative rights to install packages, create system users, and configure services.
  4. Base Software Packages: Gitea relies on Git to operate. Installing git is essential. Other recommended system utilities include wget or curl for downloading files. For example:
    sudo zypper install git wget curl
  5. Database Requirements: You can use SQLite, MySQL (MariaDB), or PostgreSQL for persistent storage. MariaDB tends to be a popular choice on openSUSE. Install MariaDB by running:
    sudo zypper install mariadb mariadb-client

    Then initialize and start the database service if needed.

Once these prerequisites are fulfilled, proceed to the next sections to learn about different installation methods for Gitea and how to choose the approach that best suits your environment.

Installation Methods

On openSUSE, Gitea can be installed in multiple ways. Two popular methods are: installing via the official openSUSE repositories (or devel:tools:scm), and performing a manual installation from the binary or source code.

1. Installing Gitea via zypper

Using zypper, the default package manager, is often the simplest method. This approach automatically handles dependencies and keeps your Gitea installation consistent with openSUSE updates:

sudo zypper addrepo https://download.opensuse.org/repositories/devel:tools:scm/openSUSE_Leap_15.5/devel:tools:scm.repo
sudo zypper refresh
sudo zypper install gitea

Once installed, Gitea resides in your system’s standard paths and can integrate well with systemd. Although this is the quickest route, repository versions lag slightly behind the latest Gitea release. However, for most production scenarios, the repository version is stable and reliable.

2. Manual Installation (Binary)

If you need the latest version or prefer more customization, download the Gitea binary from the official website. Then follow these steps:

  1. Download the Latest Binary:
    wget -O gitea https://dl.gitea.io/gitea/1.22.0/gitea-1.22.0-linux-amd64
    chmod +x gitea
    

    This command retrieves the binary, renames it to “gitea,” and gives it executable permissions.

  2. Create Gitea Directories:
    sudo mkdir -p /var/lib/gitea/{custom,data,indexers,public,log}
    sudo chown -R root:root /var/lib/gitea
    

    Adjust ownership and permissions based on whether you plan to run Gitea under a specific user account.

  3. Move Binary to System Path:
    sudo mv gitea /usr/local/bin/
    

    After placing the binary in /usr/local/bin, Gitea can be called system-wide.

By following these steps, you can successfully install Gitea either through the openSUSE repositories or via a manual binary download. Next, you will learn how to configure Gitea effectively for your environment.

Configuration Setup

After installing Gitea, the next crucial step is configuring users, directories, and the Gitea application. Proper configuration ensures that Gitea runs smoothly, with a secure and accurate environment.

User and Group Creation

It is best practice to run Gitea under a dedicated system user rather than as root. This improves security by isolating Gitea from other system processes. Commonly, users create a ‘git’ user:

sudo useradd --system --shell /bin/bash --comment 'Gitea service user' \
             --create-home --home-dir /home/git git

This command establishes a dedicated system user named “git” with a corresponding home directory. Make sure that relevant directories such as /var/lib/gitea or /etc/gitea are owned by this user to avoid permission conflicts.

Database Configuration

If you opt to use MariaDB, start by creating a new database and user for Gitea:

sudo systemctl enable mariadb
sudo systemctl start mariadb

mysql -u root -p
CREATE DATABASE giteadb;
CREATE USER 'giteauser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON giteadb.* TO 'giteauser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

This ensures that Gitea has exclusive access to the new giteadb schema and can manage data without conflicting with other databases.

app.ini Configuration File

Gitea is typically configured via an INI file titled app.ini, found in /etc/gitea or another path of your choosing. Create and configure it to define server settings, database credentials, and site configurations:

sudo mkdir -p /etc/gitea
sudo nano /etc/gitea/app.ini

A basic configuration in the [database] block might look like:

[database]
DB_TYPE  = mysql
HOST     = 127.0.0.1:3306
NAME     = giteadb
USER     = giteauser
PASSWD   = strongpassword
SSL_MODE = disable

Adjust permissions on the app.ini to ensure only the “git” user can read or modify it:

sudo chown -R git:git /etc/gitea
sudo chmod 750 /etc/gitea

This prevents unauthorized access to sensitive database credentials or other internal settings.

Service Configuration

Running Gitea as a service is highly recommended for stability and maintainability, as it enables automatic startup and supervised restarts. A typical approach is to configure a systemd service.

Systemd Service Setup

Start by creating a service file for Gitea:

sudo nano /etc/systemd/system/gitea.service

Add the following content:

[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
Wants=mariadb.service

[Service]
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

[Install]
WantedBy=multi-user.target

Enable and start the service:

sudo systemctl daemon-reload
sudo systemctl enable gitea
sudo systemctl start gitea

This registers Gitea with systemd, so it automatically starts at boot. Use systemctl status gitea to verify if Gitea is running successfully. If any errors appear, scrutinize /var/lib/gitea/log or the system journal for troubleshooting logs.

Initial Setup

Once Gitea is running, proceed with the web interface setup. By default, Gitea listens on port 3000. Access the interface by browsing:

http://your_server_ip:3000/

You are greeted by the initial configuration wizard if INSTALL_LOCK is not yet enabled. This step finalizes app-specific settings, including repository paths, internal URLs, administrative account creation, and more. Double-check that you match the wizard’s settings with those you placed in app.ini to ensure consistency.

  1. Site Configuration: Set your site/app URL, ensuring it accurately reflects your domain or IP and port setup.
  2. Database Configuration: If you have not manually configured the app.ini, you can enter the database settings here. Gitea will initialize tables when you proceed.
  3. Admin Account Creation: Provide an administrator username, password, and email. This account manages system-level tasks such as user management, repository housekeeping, and external integrations.

Install Gitea on openSUSE

Upon successful submission, Gitea finalizes and locks the configuration. You can then log in using the newly created admin credentials. If you encounter any issues with port binding or the domain URL being incorrect, re-check your app.ini file’s [server] block or the ROOT_URL parameter. Adjust any misconfigurations and restart the Gitea service as needed.

With the basic setup complete, you can now begin creating, managing, and collaborating on repositories within Gitea.

Security Considerations

Protecting your Gitea instance ensures the safety of both your code and server. A few important measures include:

Firewall Configuration

OpenSUSE’s firewall (using firewalld or SuSEfirewall2 depending on your version) can help limit unwanted access. Ensure only necessary ports—like port 3000 for Gitea’s HTTP or 22 for SSH—are open. For instance:

sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload

This configuration helps ensure external traffic can only access your Gitea instance, reducing potential attack surfaces.

SSL/TLS Setup

If you plan to expose Gitea to the internet, secure connections using TLS certificates. Reverse proxy solutions like Apache or NGINX often terminate SSL/TLS. In the [server] section of app.ini, specify PROTOCOL = https and update DOMAIN or ROOT_URL accordingly to leverage an HTTPS reverse proxy setup.

SSH Configuration

If using SSH-based repository management, confirm that the “git” user’s SSH settings are restricted to public key authentication. This helps prevent unauthorized logins. Check that PubkeyAuthentication is enabled in /etc/ssh/sshd_config and store authorized keys in /home/git/.ssh/authorized_keys as appropriate.

Post-Installation Tasks

Having completed the core Gitea configuration, there are additional measures and maintenance routines to help keep your environment stable, secure, and efficient.

Maintenance and Updates

Regular updates reduce security risks and ensure you benefit from new Gitea features. If installed via openSUSE repositories, use:

sudo zypper refresh
sudo zypper update gitea

For manual installations, download the latest Gitea binary and swap out the old executable. Always back up data prior to any upgrades to avoid unexpected downtime.

Backup Procedures

Retaining multiple backups is vital to prevent data loss. For the database, regularly perform mysqldump for MySQL or pg_dump for PostgreSQL. For repository data, rely on tar or rsync to snapshot /var/lib/gitea/data and /var/lib/gitea/repositories. An example MySQL backup command might look like:

mysqldump -u giteauser -p giteadb > /backups/giteadb_$(date +%F).sql

Keep these backups in a secure and remote location to ensure quick recovery from hardware failures or accidental deletions.

Log Management

Logs are stored in /var/lib/gitea/log by default. Frequent monitoring of these logs can provide valuable insights into performance bottlenecks, security attempts, or unusual development activity. Implement log rotation to keep log file sizes manageable and keep an eye out for error patterns that may indicate deeper issues.

Optimizing Performance

If you are hosting large projects or managing numerous user accounts, consider enabling caching and optimizing Gitea’s indexes. Take advantage of Gitea’s built-in issues indexing feature, or explore external search solutions for advanced code searching or large-scale projects. Fine-tune app.ini by configuring concurrency settings, caching durations, and repository housekeeping intervals for stable performance over time.

By addressing these tasks, you ensure your newly deployed Gitea instance remains efficient, secure, and ready to handle the evolving demands of your development workflow.

Congratulations! You have successfully installed Gitea. Thanks for using this tutorial to install the latest version of the Gitea on the openSUSE system. For additional help or useful information, we recommend you check the official Gitea website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button