How to Install Gogs on Elementary OS

Gogs is a self-hosted Git service that provides a lightweight and easy-to-use web interface for managing Git repositories. In this tutorial, we will guide you through the steps to install Gogs on Elementary OS.

Prerequisites

Before we proceed with the installation, make sure you have the following prerequisites in place:

Step 1: Install Required Dependencies

First, we need to install the required dependencies for Gogs. Run the following command in your terminal to install them:

sudo apt-get update
sudo apt-get install git nginx openssh-server imagemagick

Step 2: Create a System User for Gogs

You should not run Gogs as the root or sudo user. Therefore, we will create a new system user to run Gogs. Run the following command to create a new user:

sudo adduser --system --group --shell /bin/bash --disabled-password --home /home/git git

Step 3: Download and Install Gogs

We will now download and install Gogs. Follow the steps below to download and install Gogs:

  1. Open your web browser and go to https://gogs.io/.

  2. Click the "Download" button to download the Gogs package for Linux.

  3. Once the download is complete, extract the package to /home/git/gogs using the following command:

    sudo tar -C /home/git -zxvf gogs_*.tar.gz
    
  4. Change to the Gogs directory using the following command:

    cd /home/git/gogs
    
  5. Run the following command to start Gogs:

    ./gogs web
    

    This will start the Gogs server at http://localhost:3000/.

  6. Press Ctrl+C to stop the Gogs server.

  7. You should now configure the Gogs settings before starting the service. To do this, create a custom configuration file by copying the default one:

    cp /home/git/gogs/custom/conf/app.ini /home/git/gogs/conf/app.ini
    

    Edit the file using your favorite text editor:

    nano /home/git/gogs/conf/app.ini
    

    In this file, you can configure settings such as the port, database, and server settings.

Step 4: Create Systemd Service File for Gogs

To run Gogs as a service on your system, you need to create a Systemd service file. Run the following command to create a service file:

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

Add the following content to the file:

[Unit]
Description=Gogs
After=syslog.target
After=network.target

[Service]
User=git
Group=git
WorkingDirectory=/home/git/gogs
ExecStart=/home/git/gogs/gogs web
Restart=always
EnvironmentFile=/home/git/gogs/custom/conf/app.ini

[Install]
WantedBy=multi-user.target

Save and close the file.

Step 5: Configure Nginx

We need to configure Nginx to act as a reverse proxy for Gogs. Run the following command to create a new file for the Gogs virtual host:

sudo nano /etc/nginx/sites-available/gogs

Add the following content to the Gogs virtual host file:

server {
    listen 80;
    server_name example.com;
    access_log /var/log/nginx/gogs.access.log;
    error_log /var/log/nginx/gogs.error.log;

    client_max_body_size 50M;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://127.0.0.1:3000;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_pragma;
        proxy_cache_revalidate on;
        proxy_cache_valid 200 60m;
        add_header X-Cache-Status $upstream_cache_status;
    }
}

Make sure to replace example.com with your own domain name.

Save and close the file.

Next, we need to enable the Gogs virtual host by creating a symbolic link in the /etc/nginx/sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/gogs /etc/nginx/sites-enabled/

Finally, restart Nginx to apply the changes:

sudo systemctl restart nginx

Step 6: Start Gogs

To start the Gogs service, run the following command:

sudo systemctl start gogs

To enable Gogs to start at boot time, run the following command:

sudo systemctl enable gogs

Conclusion

Congratulations! You have successfully installed and configured Gogs on your Elementary OS system. You can access the Gogs service at http://example.com (replace example.com with your own domain name).

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!