How To Install Grafana on Ubuntu 22.04 | Easy and Full Steps
In this guide on the Orcacore website, we want to teach you How To Install Grafana on Ubuntu 22.04. Grafana is an open-source analytics and interactive visualization web application. It allows you to ingest data from a huge number of data sources, query this data, and display it on beautiful, customizable charts for easy analysis.
It is also possible to set alerts so you can quickly and easily be notified of abnormal behavior and lots more. In simple terms, Grafana allows you to transform the mountain of performance metric data collected from your applications into visualizations. This will allow you to draw conclusions and make decisions to keep your application stack healthy.
To complete this guide, you must log in to your server as a non-root user with sudo privileges and set up a basic firewall. To do this, you can follow our guide on the Initial Server Setup with Ubuntu 22.04.
And you need to have Nginx installed on your server to use it as a reverse proxy for Grafana. To do this, you can follow the installation part of our article about How to Install Nginx on Ubuntu 22.04.
Also, you need a domain name that points to your IP address. Let’s dive into the steps for How To Install Grafana on Ubuntu 22.04.
1. Add Grafana Repository To Ubuntu 22.04
Grafana is not available in the default Ubuntu repository. So you need to add the Grafana repository to your server.
First, install the required packages with the command below:
sudo apt install -y gnupg2 wget software-properties-common
Then, add the GPG public key with the following command:
sudo wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
Next, add the Grafana repo on Ubuntu 22.04 with the following command:
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
Update your local package index with the following command:
sudo apt update
2. Install Grafana with APT on Ubuntu 22.04
Here you can install Grafana with the following command:
sudo apt install grafana -y
Verify your Grafana installation by checking its version:
grafana-server -v
In your output, you will see:
**Output**
Version 9.1.6 (commit: 92461d8d1e, branch: HEAD)
3. Start and Enable Grafana Service
Now start and enable the Grafana service to start at boot with the following commands:
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
You can check that your Grafana service is active and running on Ubuntu 22.04 with the command below:
sudo systemctl status grafana-server
In your output, you will see:
**Output**
● grafana-server.service - Grafana instance
Loaded: loaded (/lib/systemd/system/grafana-server.service; enabled; vendor>
Active: **active** (**running**) since Thu 2022-09-22 09:13:38 UTC; 9s ago
Docs: http://docs.grafana.org
Main PID: 4023 (grafana-server)
Tasks: 10 (limit: 4575)
Memory: 37.3M
CPU: 1.046s
CGroup: /system.slice/grafana-server.service
└─4023 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini
4. Configure Firewall For Grafana
Grafana’s default http port is 3000, you’ll need to allow access to this port on the firewall. Here we assumed that you have enabled the UFW firewall from the requirements.
Open port 3000 on the Ubuntu 22.04 firewall:
sudo ufw allow 3000/tcp
To allow access only from a specific subnet, you can use the following command:
sudo ufw allow from **192.168.50.0/24** to any port **3000**
Reload the firewall to apply the new rules:
sudo ufw reload
5. Set up Nginx as a Reverse Proxy for Grafana on Ubuntu 22.04
At this point, you will need to configure Nginx as a reverse proxy for Grafana to access it via port 80. First, you need to create an Nginx virtual host configuration file with your favorite text editor, here we use vi:
sudo vi /etc/nginx/conf.d/grafana.conf
Add the following content to the file:
server {
server_name **example.com**;
listen 80;
access_log /var/log/nginx/grafana.log;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
When you are done, save and close the file.
To make sure that everything is ok, you can run the following command:
sudo nginx -t
In your output, you will see:
**Output**
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Next, restart the Nginx to apply the configuration changes:
sudo systemctl restart nginx
You can also check the Nginx status with the following command:
sudo systemctl status nginx
You will get the following output:
**Output**
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset:>
Active: **active** (**running**) since Thu 2022-09-22 09:25:06 UTC; 16s ago
Docs: man:nginx(8)
Process: 5595 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_proce>
Process: 5596 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (c>
Main PID: 5599 (nginx)
Tasks: 3 (limit: 4575)
Memory: 3.3M
CPU: 44ms
...
Now Nginx is configured as a reverse proxy for Grafana on Ubuntu 22.04. You can now proceed to the next step.
6. Access Grafana Dashboard Web Console
At this point, you can access the Grafana web interface on Ubuntu 22.04 by typing your domain name in your web browser, followed by 3000:
http://**your-domain-name**:3000
You will see the login interface. Enter admin for the username and password and click Log in.

Then you’ll be asked to renew your password and click submit.

When you have changed your password, you will see the Grafana welcome dashboard:

Now you can proceed to the next step to secure your Grafana service.
7. Secure Grafana with Let’s Encrypt
At this point, you will need to install the Certbot client package to install and manage the Let’s Encrypt SSL. To do this, run the command below:
sudo apt install certbot python3-certbot-nginx -y
Once the installation is finished, run the following command to install the Let’s Encrypt SSL on your website:
sudo certbot --nginx -d **example.com**
You will be asked to enter your Email address and accept the terms of service:

Now you can load your website by https://
and notice your browser’s security indicator.
https://**your-domain**
As you know, Let’s Encrypt certificates are valid for 90 days. Because of this, you can renew your process.
You can test the renewal process with certbot:
sudo certbot renew --dry-run

Conclusion
At this point, you have learned to install Grafana on Ubuntu 22.04 and set up Nginx as a reverse proxy for it. Also, you have learned to secure Grafana with Let’s Encrypt.
Hope you enjoy it. Please subscribe to us on Facebook, X, and YouTube.
You may also like to read the following articles:
Installing bmon on Ubuntu 22.04
Network Monitoring with OpManager on Debian 12
Install Grafana on AlmaLinux 9
Alternative Solutions for Installing Grafana on Ubuntu 22.04
While the above steps provide a solid method for installing Grafana with Nginx as a reverse proxy, here are two alternative approaches that may be suitable for different needs or preferences.
1. Using Docker Compose
Docker Compose provides a more containerized approach, simplifying deployment and management. This method is particularly useful if you already utilize Docker for other services or prefer a more isolated environment for Grafana. This method for How To Install Grafana on Ubuntu 22.04 is good for those who prefer working with containers.
Explanation:
This approach leverages Docker to containerize Grafana, making it easier to manage dependencies and isolate the application. Docker Compose further simplifies this by defining the entire service stack (Grafana, potentially other data sources) in a single docker-compose.yml
file. This promotes consistency and reproducibility across different environments.
Steps:
- Install Docker and Docker Compose: If you haven’t already, install Docker and Docker Compose on your Ubuntu 22.04 server.
- Create a
docker-compose.yml
file: Create a new file nameddocker-compose.yml
in a directory of your choice. -
Define the Grafana service: Add the following content to your
docker-compose.yml
file:version: "3.8" services: grafana: image: grafana/grafana:latest ports: - "3000:3000" volumes: - grafana_data:/var/lib/grafana restart: unless-stopped volumes: grafana_data:
Explanation of the
docker-compose.yml
:version: "3.8"
: Specifies the Docker Compose file version.services: grafana:
: Defines the Grafana service.image: grafana/grafana:latest
: Specifies the Docker image to use for Grafana (the latest stable version).ports: - "3000:3000"
: Maps port 3000 on the host to port 3000 in the container, allowing access to Grafana.volumes: - grafana_data:/var/lib/grafana
: Creates a persistent volume namedgrafana_data
to store Grafana’s data, ensuring data persistence even if the container is stopped or restarted.restart: unless-stopped
: Configures the container to restart automatically unless explicitly stopped.volumes: grafana_data:
: Defines thegrafana_data
volume.
-
Start Grafana: Navigate to the directory containing your
docker-compose.yml
file in the terminal and run the following command:docker-compose up -d
This command will download the Grafana image (if it’s not already present), create a container, and start Grafana in detached mode (running in the background).
- Access Grafana: Open your web browser and navigate to
http://your_server_ip:3000
to access the Grafana web interface.
2. Using Snap Package
Ubuntu offers Snap packages, which are containerized software packages that are easy to install and update. This provides a simplified installation process compared to manually adding repositories.
Explanation:
Snap packages are self-contained applications that include all their dependencies. This eliminates the need to manually install dependencies or manage repositories, making the installation process more straightforward. Snaps also offer automatic updates, ensuring you always have the latest version of Grafana.
Steps:
-
Install Grafana: Open a terminal and run the following command to install Grafana using Snap:
sudo snap install grafana
-
Configure Grafana’s Listening Address: By default, the snap package might configure Grafana to listen only on the loopback address (127.0.0.1). This means it’s only accessible from the same machine. If you want to access Grafana from other machines, you might need to configure it to listen on all interfaces or a specific network interface.
- To change the listening address, you can use the
grafana.override
configuration option. However, modifying snap configurations directly might be complex. - If you’re facing issues with accessing Grafana remotely via the snap package, consider using the Docker Compose approach or installing Grafana using the APT method as described in the original article. These methods offer more flexibility in configuring network access.
- To change the listening address, you can use the
-
Start and Enable Grafana: The Snap package should automatically start Grafana after installation. You can verify its status with:
sudo snap services grafana
If it’s not running, you can start it using:
sudo snap start grafana
To ensure Grafana starts automatically on boot, enable the service:
sudo snap enable grafana
-
Configure Firewall: As with the original method, you’ll need to allow access to port 3000 on your firewall:
sudo ufw allow 3000/tcp
sudo ufw reload
- Access Grafana: Open your web browser and navigate to
http://your_server_ip:3000
to access the Grafana web interface.
These alternative solutions offer different approaches to installing Grafana on Ubuntu 22.04. Docker Compose provides a containerized and reproducible deployment, while Snap packages offer a simplified installation and update process. Choose the method that best suits your needs and technical preferences. Regardless of the method you choose, securing your Grafana installation remains crucial for protecting your data and ensuring the integrity of your monitoring system.