Install Loki on Ubuntu 20.04

Install Loki on Ubuntu 20.04

Loki is an open-source log aggregation system developed by Grafana Labs. Loki is a datastore that optimized for storing log data. It can be easily integrated with Grafana as datasource for viewing logs.

This tutorial demonstrates how to install Loki on Ubuntu 20.04.

Install Loki

Get the latest version tag of Loki release from GitHub. Then assign version tag to variable.

LOKI_VERSION=$(curl -s "" | grep -Po '"tag_name": "v\K[0-9.]+')

Create a new directory to store Loki binary and configuration file.

sudo mkdir /opt/loki

Download archive from releases page of the Loki repository.

sudo wget -qO /opt/loki/loki.gz "${LOKI_VERSION}/"

Extract binary file from archive:

sudo gunzip /opt/loki/loki.gz

Set execute permission for file:

sudo chmod a+x /opt/loki/loki

In /usr/local/bin directory we can create a symbolic link to the loki command:

sudo ln -s /opt/loki/loki /usr/local/bin/loki

Now loki command is available for all users as a system-wide command.

Download configuration file for Loki:

sudo wget -qO /opt/loki/loki-local-config.yaml "${LOKI_VERSION}/cmd/loki/loki-local-config.yaml"

To verify installation, we can check Loki version:

loki -version

Run Loki as a service

We can configure systemd for running Loki as a service. Create a systemd unit file:

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

Add the following content to the file:

Description=Loki log aggregation system

ExecStart=/opt/loki/loki -config.file=/opt/loki/loki-local-config.yaml


Start Loki service:

sudo service loki start

To make sure that Loki service is running, you can use the following command:

sudo service loki status

Also you can stop or restart the service:

sudo service loki stop
sudo service loki restart

To enable Loki to start on boot, run the following command:

sudo systemctl enable loki

Uninstall Loki

If you decided to completely remove the Loki, stop the service and remove a systemd unit file.

sudo service loki stop
sudo systemctl disable loki
sudo rm -rf /etc/systemd/system/loki.service
sudo systemctl daemon-reload
sudo systemctl reset-failed

Delete the installation directory:

sudo rm -rf /opt/loki

Remove symbolic link:

sudo rm -rf /usr/local/bin/loki

The 2 Comments Found

  1. Avatar
    Gerard Reply

    Love this. No endless webinars or proza filled blog posts, just the commands to do a quick lab test with Loki.

    Thank you!

Leave a Comment

Cancel reply

Your email address will not be published.