Install Grafana on Linux: Step-by-Step DevOps Monitoring Guide
Introduction
If you are managing modern infrastructure, deploying code, or maintaining servers, you already know that flying blind is not an option. Without proper observability, a server crash or a CPU spike is a mystery you have to solve while your application is down. This is where Grafana comes in. As one of the most powerful open-source visualization and analytics platforms, Grafana allows DevOps engineers to monitor everything from Linux server health to complex containerized application metrics.
In this comprehensive, step-by-step guide, I will show you exactly how to install Grafana on a Linux server (specifically targeting Ubuntu/Debian distributions). But we won't just copy and paste commands. I wrote this guide for junior developers and system administrators, meaning we will break down why we are running each command, where Grafana stores its files, and how to secure it properly for a production environment.
- Introduction
- Prerequisites: What You Need Before Starting
- Step 1: Update Your Linux Server
- Step 2: Install Required Core Packages
- Step 3: Add the Official Grafana GPG Key and Repository
- Step 4: Install Grafana
- Step 5: Start and Enable the Systemd Service
- Step 6: Verify the Grafana Port (3000)
- Step 7: Configure the UFW Firewall (Crucial for Cloud Servers)
- Step 8: Access the Grafana UI in Your Browser
- Step 9: The First Password Change
- Step 10: Exploring the Grafana Dashboard & Next Steps
- Final Thoughts on Observability
- Frequently Asked Questions
Prerequisites: What You Need Before Starting
Before diving into the terminal, ensure your environment meets these basic requirements to avoid installation headaches:
- A Linux Server: A machine running Ubuntu 20.04, 22.04 LTS, or a similar Debian-based distribution.
- Privileges: A user account with
sudo(root) privileges to install packages and modify system services. - Basic Resources: At least 1 CPU core and 1GB of RAM. (Grafana is lightweight, but your data sources like Prometheus will require more resources as you scale).
- Network Access: The ability to open port 3000 on your server's firewall or cloud provider's security group.
Step 1: Update Your Linux Server
The golden rule of system administration is to never install new software on stale packages. We start by updating the local package index and upgrading existing packages to their latest versions. This ensures compatibility and patches any underlying security vulnerabilities before we introduce Grafana to the system.
sudo apt update
sudo apt upgrade -y
What do these commands do? apt update fetches the latest list of available packages from the Ubuntu repositories, while apt upgrade -y actually installs the newer versions. The -y flag simply auto-confirms the prompt so you don't have to press 'Y' manually.
Troubleshooting Tip: If you are running these commands and suddenly hit a 429 Too Many Requests error on your apt update, do not panic. This is a common rate-limiting issue with Ubuntu's archive servers. You can resolve it quickly by following this dedicated fix:
How to Fix 429 Too Many Requests Error in Ubuntu APT Update
Step 2: Install Required Core Packages
Grafana isn't always included in the default Linux repositories by default, which means we have to fetch it directly from Grafana Labs. To do this securely, our server needs a few utility tools installed first.
sudo apt install wget curl software-properties-common net-tools -y
As a junior DevOps engineer, it is crucial to understand your toolset. Here is exactly what we just installed:
- wget & curl: Command-line utilities used for downloading files and communicating with web servers. We will use them to pull down Grafana's security keys.
- software-properties-common: This package provides an abstraction of the used apt repositories. It allows you to easily manage independent software vendor (ISV) software sources.
- net-tools: This provides the
netstatcommand, which we will use later to verify that Grafana is actively listening on its assigned network port.
Step 3: Add the Official Grafana GPG Key and Repository
Linux security relies heavily on cryptography. Before Ubuntu will allow you to install Grafana, you must prove that the software actually comes from Grafana Labs and hasn't been tampered with. We do this by importing their GPG (GNU Privacy Guard) key.
# Download the GPG key and add it to your system's trusted keys
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
# Add the Grafana stable repository to your APT sources list
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
By running the tee command, we have created a new file inside /etc/apt/sources.list.d/. Now, whenever we tell our server to update or install software, it knows to look at Grafana's official servers in addition to the standard Ubuntu servers. We are installing the OSS (Open Source Software) version, which is free and perfect for our needs.
Step 4: Install Grafana
Because we just added a brand new repository, we must run apt update one more time to index all the new Grafana packages available to us. Once indexed, the installation is a single command.
sudo apt update
sudo apt install grafana -y
Where does Grafana live on your server?
Knowing where configurations are stored is what separates a beginner from a mid-level DevOps engineer. After this installation, Grafana scatters its files in logical Linux directories:
- Binary Executable:
/usr/sbin/grafana-server - Configuration File:
/etc/grafana/grafana.ini(You will edit this file later if you want to set up SMTP email alerts or change the default port). - Log Files:
/var/log/grafana/grafana.log(Always check here if Grafana refuses to start). - SQLite Database & Plugins:
/var/lib/grafana/(This holds all your user data, dashboard setups, and downloaded plugins).
Step 5: Start and Enable the Systemd Service
Simply installing the software doesn't mean it is running. In modern Linux systems, background applications (daemons) are managed by systemd. We need to tell systemd to start Grafana right now, and more importantly, to start it automatically if the server ever reboots.
# Start the service immediately
sudo systemctl start grafana-server
# Enable the service to launch on system boot
sudo systemctl enable grafana-server
# Check the health and status of the service
sudo systemctl status grafana-server
When you run the status command, look for the green text that says active (running). If you see this, the core installation was a complete success! Press q on your keyboard to exit the status screen and return to your terminal prompt.
Step 6: Verify the Grafana Port (3000)
By default, the Grafana web interface listens on port 3000. Let's verify that the server is actually binding to this port. This is where the net-tools package we installed earlier comes in handy.
netstat -tpln
You should see an output showing that a process called grafana-server is actively in a LISTEN state on 0.0.0.0:3000 or :::3000. This means it is ready to accept web traffic.
Step 7: Configure the UFW Firewall (Crucial for Cloud Servers)
If you are running this on a local virtual machine, you might be able to access it immediately. However, if you are running this on a cloud provider (like AWS EC2, DigitalOcean, or Azure), your Linux firewall will block incoming requests to port 3000 by default.
We need to open the port using UFW (Uncomplicated Firewall).
# Ensure the firewall is active
sudo ufw enable
# Allow TCP traffic on port 3000
sudo ufw allow 3000/tcp
# Reload the firewall to apply the new rules
sudo ufw reload
# Verify the rule was added
sudo ufw status
Note for Cloud Users: If you are on AWS, you must also go into your AWS Console -> EC2 -> Security Groups, and add an Inbound Rule allowing Custom TCP on port 3000. The Linux UFW firewall and the AWS Security Group are two separate barriers. Both must be open.
Step 8: Access the Grafana UI in Your Browser
It is time to reap the rewards of your hard work. Open your favorite web browser and navigate to your server's IP address followed by port 3000.
http://your-server-ip-address:3000
Example: http://172.16.21.101:3000
You will be greeted by the sleek Grafana login screen. To log in for the first time, use the default factory credentials:
- Default Username:
admin - Default Password:
admin
Step 9: The First Password Change
The instant you log in, Grafana will intercept your session and force you to change the password. Do not click "Skip". Leaving a default admin/admin password on a monitoring dashboard that exposes your server's architecture is a massive security risk, especially if your port 3000 is exposed to the public internet.
Create a strong, unique password. Once submitted, you will be redirected to the main dashboard.
Step 10: Exploring the Grafana Dashboard & Next Steps
Congratulations! You have successfully installed and secured Grafana.
What Should You Do Next?
Grafana by itself is just a visualization tool; it is essentially an empty canvas. To make it useful, you need to feed it data. Here is what your immediate next steps should look like in your DevOps journey:
- Install Prometheus: Grafana and Prometheus are the peanut butter and jelly of the DevOps world. Prometheus scrapes and stores the time-series data (like CPU usage, memory limits, and HTTP requests), and Grafana turns that raw data into beautiful, readable graphs. You will need to add Prometheus as a "Data Source" in the Grafana settings.
- Set Up an Nginx Reverse Proxy: Navigating to
http://your-ip:3000is fine for testing, but it is not suitable for production. The standard practice is to configure an Nginx reverse proxy to route traffic from a clean domain (likemonitor.yourdomain.com) on port 80/443 directly to Grafana's port 3000 internally. - Secure with SSL/TLS: Once you have Nginx set up, use Certbot to apply a free Let's Encrypt SSL certificate, ensuring all your monitoring traffic is encrypted via HTTPS.
Final Thoughts on Observability
Installing Grafana on a Linux server is a foundational DevOps skill. By walking through this manual process—rather than just running a Docker container—you gain a much deeper understanding of how the system interacts with package managers, systemd, and the kernel's network stack. You are now ready to start building dashboards and writing PromQL queries to keep your infrastructure healthy and resilient.
Frequently Asked Questions
Is Grafana actually free for commercial use?
Yes, the OSS (Open Source Software) edition of Grafana is entirely free to use, even for commercial and enterprise environments. Grafana Labs monetizes by offering a managed cloud version and an Enterprise version with advanced plugins, but the core features remain open source.
Can I install Grafana using Docker instead?
Absolutely. Running docker run -d -p 3000:3000 --name=grafana grafana/grafana-enterprise will spin up an instance instantly. However, managing Grafana directly on the Linux host (bare-metal approach) as shown in this guide is highly recommended for learning the fundamentals of Linux service management.
Where are my Grafana dashboards saved?
By default, Grafana stores all dashboard JSON files, user credentials, and data source configurations in a local SQLite database located at /var/lib/grafana/grafana.db. If you are migrating servers, backing up this file is essential. For enterprise scaling, you can configure Grafana to use MySQL or PostgreSQL instead.
How do I restart Grafana if it crashes?
Because we configured systemd, you can manage the application state just like any other Linux service. If you make a configuration change in grafana.ini, simply run:
sudo systemctl restart grafana-server
Can I change the default port from 3000 to port 80?
You can, but it is highly discouraged. On Linux, ports below 1024 are "privileged" ports and require root access to bind to. Running Grafana as root is a major security risk. The industry standard is to leave Grafana on port 3000 and use Nginx or Apache as a reverse proxy on port 80/443 to forward the traffic securely.