Data visualization tools make it easy to discern useful information and draw a conclusion from large and complicated data sets. Grafana is one of the popular and open-source interactive data visualization tools that let you analyze and visualize your data from all the sources into a unified dashboard.

It allows exploring the data through queries, visualizing the data using plenty of visualization components such as graphs, histograms, heatmaps, etc., and setting up alerts and notifications. Grafana supports a number of data sources, such as Prometheus, Graphite, Elasticsearch, PostgreSQL, and many others. Here's how to set up Grafana on Ubuntu.

1. Install Grafana From the Official Repository

You can install Grafana on Ubuntu using their official repository and the APT package manager. To begin the installation, open the terminal and use the following command to install some prerequisites:

        sudo apt install -y apt-transport-https software-properties-common
    

Then, download Grafana's GPG key:

        wget -q -O /usr/share/keyrings/grafana.key https://packages.grafana.com/gpg.key
    

After installing the prerequisites and downloading the GPG key, add the repository and install Grafana.

For Enterprise Edition

Issue the following command to add the GPG key and repository of Grafana to your system's APT sources:

        echo deb [signed-by=/usr/share/keyrings/grafana.key] https://packages.grafana.com/enterprise/deb stable main | sudo tee -a /etc/apt/sources.list.d/grafana.list
    

Then, update the repository index:

        sudo apt update
    

Once the update is complete, issue the following command to install the Grafana Enterprise edition:

        sudo apt install grafana-enterprise
    

For OSS Edition

Issue the following command to add Grafana's GPG key and repository to your system’s APT sources:

        echo deb [signed-by=/usr/share/keyrings/grafana.key] https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
    

Next, update the repository index by running:

        sudo apt-get update
    

Then, issue the following command to install the Grafana OSS edition:

        sudo apt-get install grafana 
    

2. Install Grafana on Ubuntu Using the DEB Package

Alternatively, you can also install Grafana by installing the DEB package available at the official website using dpkg. You can either manually download the package from the website or use the commands mentioned below.

Download: Grafana

To begin the installation, open the terminal and download the Grafana Enterprise or OSS edition based on what you want to install on your system.

For Enterprise Edition

        wget https://dl.grafana.com/enterprise/release/grafana-enterprise_9.1.5_amd64.deb
    

For OSS Edition

        wget https://dl.grafana.com/oss/release/grafana_9.1.5_amd64.deb
    

Then, issue the following command to install the Grafana DEB package:

        sudo dpkg -i grafana*_amd64.deb
    

3. Install Grafana on Ubuntu Using Binary Files

You can also install Grafana using the binary TAR.GZ file available on the official website. You can either manually download the binary file from the website or use the commands below.

Download: Grafana

To begin the installation, open the terminal and use the following commands to download the TAR.GZ file.

For Enterprise Edition

        wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.1.5.linux-amd64.tar.gz
    

For OSS Edition

        wget https://dl.grafana.com/oss/release/grafana-9.1.5.linux-amd64.tar.gz
    

Now extract the TAR.GZ file using the following command:

        sudo tar -zxvf grafana-*.tar.gz
    

The aforementioned command will extract the contents of the archive to a directory with the same base name as the archive version you have downloaded. You can find this new directory under your current directory.

How to Manage Grafana Services on Ubuntu

Grafana server does not start automatically after installation. Based on the installation methods you used, you can manually start its service using either systemctl or by executing the binary.

If you installed Grafana from the official repository or using the DEB package, use the following systemd commands to manage the Grafana server:

To start the Grafana service, use:

        sudo systemctl daemon-reload
sudo systemctl start grafana-server

To check the service's status, use:

        sudo systemctl status grafana-server
    

To ensure Grafana's service automatically starts at boot, use:

        sudo systemctl enable grafana-server.service
    

If you installed Grafana using the TAR.GZ file, use the following commands to manage the Grafana server:

Move into the Grafana directory using the cd command:

        cd /usr/local/Grafana
    

Now execute the binary to start the Grafana server.

        ./bin/grafana-server web
    

Use Ctrl + C to stop it.

How to Access Grafana's Web Interface

Grafana listens to default HTTP port 3000. For external access, you will need to open this port in the firewall using the following command:

        sudo ufw allow 3000/tcp
    

To access Grafana, open any browser and navigate to your system's IP address and port 3000.

        http://ip-address:3000
    

It will open the following Grafana Login screen. Log in using the following default credentials:

Email or username: admin

Password: admin

grafana login webpage

Then, it will prompt you to set a new password for your Grafana login. After setting the new password, you will be redirected to the Grafana dashboard.

Grafana Dashboard

How to Set Up Grafana on Ubuntu

Follow the below steps to set up Grafana by adding a data source and creating a new dashboard.

Add a Data Source in Grafana

To add a data source in Grafana, follow the below steps:

  1. On the left sidebar of the Grafana dashboard, click the Settings icon.
  2. Click Add data source and then choose data source type from the list of all supported data sources.
  3. Fill out the necessary parameters (URL or host details, authentication or authorization details, etc.) to configure the data source.
  4. Once done, click Save & test. If you see a Database Connection OK message, it means all went well and your data source is connected.

Create a New Dashboard

To create a new dashboard in Grafana, follow the below steps:

  1. Hover the cursor over the Dashboards icon in the left sidebar and click New dashboard.
  2. Click Add a new panel and under the Query tab, select Data source. Next to Data source, there will be Query options. Configure the necessary settings for the query. On the right sidebar, select the visualization type and name the panel.
  3. Once done, click Save in the top-right corner, name the dashboard and save it. After that, Grafana will automatically take you back to the dashboard.

How to Uninstall Grafana From Ubuntu

Based on how you installed Grafana, there are different ways to uninstall it. If you installed Grafana from the official APT repository or through the DEB package, you can uninstall it using:

        sudo apt purge grafana
    

If you installed Grafana using the binary file, you can uninstall it by removing both the Grafana directory and the TAR.GZ file:

        sudo rm -r grafana-*tar.gz grafana-*
    

Visualize Your Data on Ubuntu With Customizable Dashboards

With the help of customizable dashboards in Grafana, you can visualize large and complex data from various data sources. Given the various methods of installing Grafana, you can choose any method at your convenience.

If you don't want to install and set up Grafana on your system, there are several other data visualization methods that you can use instead.