YouTube Icon

Code Playground.

How to Install Gitea on Ubuntu 18.04

CFG

How to Install Gitea on Ubuntu 18.04

Gitea is a self-facilitated open-source git worker written in Go. It is a fork of Gogs . Gitea incorporates a store record supervisor, venture issue following, clients administrations, notices, implicit wiki, and considerably more. 

Gitea is a lightweight application and can be introduced on low-controlled frameworks. In the event that you are looking for an option in contrast to Gitlab with an a lot littler memory impression and you needn't bother with all the fancy odds and ends that Gitlab offers, at that point you should attempt Gitea. 

This instructional exercise discloses how to introduce and arrange Gitea on Ubuntu 18.04. Similar directions apply for Ubuntu 16.04 and some other Debian-based circulation. 

Prerequisites

Gitea upholds SQLite, PostgreSQL , and MySQL/MariaDB as information base backends. 

We'll utilize SQLite as the information base for Gitea. On the off chance that SQLite isn't introduced on your Ubuntu framework you can introduce it by entering the accompanying orders as sudo client : 

sudo apt update
sudo apt install sqlite3

Installing Gitea

Gitea gives Docker pictures and can be introduced from source, double, and as a bundle. We'll introduce Gitea from paired. 

Install Git

The initial step is to introduce Git on your worker: 

sudo apt update
sudo apt install git

Confirm the establishment by showing the Git variant: 

git --version
git version 2.17.1

Create a Git user

Make another framework client which will show the Gitea application to composing: 

sudo adduser --system --group --disabled-password --shell /bin/bash --home /home/git --gecos 'Git Version Control' git

The order will make another client and gathering named git, and set the home registry to/home/git. The yield will look something like underneath: 

Adding system user `git' (UID 111) ...
Adding new group `git' (GID 116) ...
Adding new user `git' (UID 111) with group `git' ...
Creating home directory `/home/git' ...

Download Gitea binary

Visit the Gitea Download page and download the most recent double for your design. At the hour of composing, the most recent adaptation is 1.10.2. In the event that there is another form accessible, change the VERSION variable in the order underneath. 

Download the Gitea paired in the/tmp registry utilizing the accompanying wget order: 

VERSION=1.10.2
sudo wget -O /tmp/gitea https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-linux-amd64

The gitea paired can run from any area. We'll follow the show and move the paired to the/usr/neighborhood/receptacle catalog: 

sudo mv /tmp/gitea /usr/local/bin

Make the parallel executable: 

sudo chmod +x /usr/local/bin/gitea

Run the orders beneath to make the registries and set the necessary consents and proprietorship : 

sudo mkdir -p /var/lib/gitea/{custom,data,indexers,public,log}
sudo chown git: /var/lib/gitea/{data,indexers,log}
sudo chmod 750 /var/lib/gitea/{data,indexers,log}
sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

The registry structure above is suggested by the authority Gitea documentation. 

The authorizations of the/and so forth/gitea index are set to 770 with the goal that the establishment wizard can make the setup record. When the establishment is finished, we'll set more prohibitive authorizations. 

Create a Systemd Unit File

Gitea gives a Systemd unit record that is as of now arranged to coordinate our arrangement. 

Download the record to the/and so on/systemd/framework/index by composing: 

sudo wget https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service -P /etc/systemd/system/

When done, empower and start the Gitea administration: 

sudo systemctl daemon-reload
sudo systemctl enable --now gitea

Confirm that the administration is begun effectively: 

sudo systemctl status gitea
? gitea.service - Gitea (Git with a cup of tea)
   Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-01-04 21:27:23 UTC; 3s ago
 Main PID: 14804 (gitea)
    Tasks: 9 (limit: 1152)
   CGroup: /system.slice/gitea.service
           ??14804 /usr/local/bin/gitea web --config /etc/gitea/app.ini
...

Configure Gitea

Since Gitea is downloaded and running, the time has come to conclude the establishment through the web interface. 

As a matter of course, Gitea tunes in for associations on port 3000 on all organization interfaces. 

On the off chance that you have a UFW firewall running on your worker, you'll have to open the Gitea port: 

To permit traffic on port 3000, enter the accompanying order: 

sudo ufw allow 3000/tcp

Open your program, type http://YOUR_DOMAIN_IR_IP:3000, and a screen like the accompanying will show up: 

Information base Settings: 

  • Information base Type: SQLite3 
  • Way: Use a flat out way,/var/lib/gitea/information/gitea.db 
  • Application General Settings: 
  • Site Title: Enter your association name. 
  • Vault Root Path: Leave the default/home/git/gitea-archives. 
  • Git LFS Root Path: Leave the default/var/lib/gitea/information/lfs. 
  • Run As Username: git 
  • SSH Server Domain: Enter your area or worker IP address. 
  • SSH Port: 22, change it if SSH is tuning in on other Port 
  • Gitea HTTP Listen Port: 3000 
  • Gitea Base URL: Use http and your space or worker IP address. 
  • Log Path: Leave the default/var/lib/gitea/log 

You can change the settings whenever by altering the Gitea arrangement document. 

When done, hit the "Introduce Gitea" button. The establishment is moment. At the point when finished you will be diverted to the login page. 

Snap on the "Join presently" interface. The initially enlisted client is consequently added to the Admin gathering. 

Change the consents of the Gitea setup record to peruse just utilizing: 

sudo chmod 750 /etc/gitea
sudo chmod 640 /etc/gitea/app.ini

That is it. Gitea has been introduced on your Ubuntu machine. 

Configuring Nginx as SSL Termination Proxy

This progression is discretionary, yet it is energetically suggested. To utilize Nginx as an opposite intermediary you have to have an area or subdomain highlighting your worker public IP. In this instructional exercise, we will utilize git.example.com. 

To start with, introduce Nginx and produce a free Let's Encrypt SSL declaration utilizing the aides beneath: 

Step by step instructions to Install Nginx on Ubuntu 18.04 

Secure Nginx with Let's Encrypt on Ubuntu 18.04 

When done, open your content manager and alter the area worker block document: 

sudo nano /etc/nginx/sites-enabled/git.example.com

/etc/nginx/sites-enabled/git.example.com

server {
    listen 80;
    server_name git.example.com;

    include snippets/letsencrypt.conf;
    return 301 https://git.example.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name git.example.com;

    proxy_read_timeout 720s;
    proxy_connect_timeout 720s;
    proxy_send_timeout 720s;

    client_max_body_size 50m;

    # Proxy headers
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;

    # SSL parameters
    ssl_certificate /etc/letsencrypt/live/git.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/git.example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/git.example.com/chain.pem;
    include snippets/letsencrypt.conf;
    include snippets/ssl.conf;

    # log files
    access_log /var/log/nginx/git.example.com.access.log;
    error_log /var/log/nginx/git.example.com.error.log;

    # Handle / requests
    location / {
       proxy_redirect off;
       proxy_pass http://127.0.0.1:3000;
    }
}

Remember to supplant git.example.com with your Gitea area and set the right way to the SSL testament records. The HTTP traffic is diverted to HTTPS 

Restart the Nginx administration for changes to produce results: 

sudo systemctl restart nginx

Next, change the Gitea area and root url. To do as such, open the design document and alter the accompanying lines: 

sudo nano /etc/gitea/app.ini

/etc/gitea/app.ini

[server]
DOMAIN           = git.example.com
ROOT_URL         = https://git.example.com/

Restart the Gitea administration by composing: 

sudo systemctl restart gitea

Now, Gitea intermediary is arranged, and you can get to it at: https://git.example.com 

Configuring Email Notifications

With the end goal for Gitea to have the option to send notice messages, you can either introduce Postfix or utilize some value-based mail administration, for example, SendGrid, MailChimp, MailGun, or SES. 

To empower email warnings, open the arrangement record and alter the accompanying lines: 

sudo nano /etc/gitea/app.ini

/etc/gitea/app.ini

[mailer]
ENABLED = true
HOST    = SMTP_SERVER:SMTP_PORT
FROM    = SENDER_EMAIL
USER    = SMTP_USER
PASSWD  = YOUR_SMTP_PASSWORD

Ensure you put the right SMTP worker data. 

Restart the Gitea administration for changes to produce results: 

sudo systemctl restart gitea

To check the settings and send a test email, sign in to Gitea, and go to: Site Administration > Configuration > SMTP Mailer Configuration. 

Gitea additionally permits you to interface with Slack by making a web webhook and send notices to your Slack channels . 

Upgrading Gitea

To move up to the most recent Gitea adaptation, basically download and supplant the double. 

Stop the Gitea administration: 

  1. sudo systemctl stop gitea
  2. Download the latest Gitea version and move it to the /usr/local/bin directory:

    VERSION=<THE_LATEST_GITEA_VERSION>wget -O /tmp/gitea https://dl.gitea.io/gitea/${VERSION}/gitea-${VERSION}-linux-amd64sudo mv /tmp/gitea /usr/local/bin

     

  3. Make the binary executable:

    sudo chmod +x /usr/local/bin/gitea
  4. Restart the Gitea service:

    sudo systemctl restart gitea

That is it. 

Conclusion

This instructional exercise strolled you through the establishment of Gitea on Ubuntu 18.04. 

You should now visit the Gitea documentation page and figure out how to design your Gitea example and make your first venture. 

On the off chance that you have questions, don't hesitate to leave a remark underneath.




CFG