Monitoring Tools

A Guide to Install Grafana on Ubuntu 22.04

In this tutorial, you will learn how to install Grafana on Ubuntu 22.04 with PostgreSQL DB. We shall install Grafana Enterprise  and Open Source CLI version 9.1.6.

Grafana is open source visualization and analytics software. It allows you to query, visualize, alert on, and explore your metrics no matter where they are stored. In plain English, it provides you with tools to turn your time-series database (TSDB) data into beautiful graphs and visualizations.


By default, Grafana installs with and uses SQLite, which is an embedded database stored in the Grafana installation location. Here we’re installing PostgreSQL database.

Let’s get started with the installation process.

Install Grafana on Ubuntu 22.04

Step 1 – Keep the server up to date

# apt update -y

# apt upgrade -y

Step 2 – Install PostgreSQL database

Install PostgreSQL database using following command:

# apt install -y postgresql

Start and enable PostgreSQL service:

# systemctl start postgresql

# systemctl enable postgresql

Next, we need to create a database for Grafana and assign it a username and password for authentication.

# sudo -u postgres psql

postgres=# CREATE DATABASE grafana;


postgres=# CREATE USER grafana WITH PASSWORD ‘grafana’;


postgres=# GRANT ALL PRIVILEGES ON DATABASE grafana TO grafana;


postgres=#\c grafana

You are now connected to database “grafana” as user “postgres”.

postgres=#CREATE TABLE session ( key CHAR(16) NOT NULL, data bytea, expiry INT NOT NULL, PRIMARY KEY (key));


postgres=# \q


  • Use your own database name as well as username and set strong password.

Step 2 – Install required package and add GPG key

# apt-get install apt-transport-https -y

# wget -q -O – | sudo apt-key add –

Step 3 – Add this repository for stable releases

Latest Enterprise edition

# echo “deb stable main” | sudo tee -a /etc/apt/sources.list.d/grafana.list

Latest OSS release

# echo “deb stable main” | sudo tee -a /etc/apt/sources.list.d/grafana.list

Step 4 – Install Grafana Enterprise

After you add the repository first update the server and install the Grafana Enterprise.

# apt-get update -y
# apt-get install grafana-enterprise -y

To install OSS release:

# apt-get update -y

# apt-get install grafana -y

Configure PostgreSQL:

First edit pg_hba.conf file.

# nano /etc/postgresql/14/main/pg_hba.conf

Add following lines:

host all grafana trust
local all grafana trust

Save and exit.

Finally, modify default database configuration and set to PostgreSQL database configuration.

# nano /etc/grafana/grafana.ini

# You can configure the database connection by specifying type, host, name, user and password
# as separate properties or as on string using the url properties.

# Either “mysql”, “postgres” or “sqlite3”, it’s your choice
type = postgres
host =
name = grafana
user = grafana
password = grafana


  • Change the name, user, and password as your configurations.

Save and exit.

To start and enable the service and verify that the service has started: grafana-server.service.

# systemctl start grafana-server.service
# systemctl enable grafana-server.service

Package details

  • Default file (environment vars) to /etc/default/grafana-server
  • Configuration file to /etc/grafana/grafana.ini
  • systemd service (if systemd is available) name grafana-server.service
  • The default configuration sets the log file at /var/log/grafana/grafana.log
  • HTML/JS/CSS and other Grafana files at /usr/share/grafana

Step 5 – Log in into dashboard

To log in to Grafana for the first time:

  • Open your web browser and go to http://localhost:3000/. The default HTTP port that Grafana listens to is 3000 unless you have configured a different port.
  • On the login page, enter admin for username and password.
  • Click Log In. If login is successful, then you will see a prompt to change the password.
  • Click OK on the prompt, then change your password.

A Guide to Install Grafana on Ubuntu 22.04 - HostnExtra

The installation is completed successfully.

In this tutorial, you have learnt how to install Grafana on Ubuntu 22.04.

Related Articles