How to Install Grafana on Ubuntu: Complete Setup & Configuration Guide
Grafana is one of the most powerful open-source platforms for data visualization and infrastructure monitoring. Whether you're tracking server performance, application metrics, or business KPIs, Grafana's flexible dashboards and broad data source support make it an indispensable tool for any systems administrator or DevOps engineer.
This comprehensive guide walks you through every step of installing Grafana on Ubuntu β from initial system preparation to configuring data sources, building your first dashboard, setting up alerts, and securing your deployment.
> Prerequisites: A running Ubuntu server (20.04 or 22.04 LTS recommended), sudo privileges, and a stable internet connection. If you need a reliable server to host your Grafana instance, consider VPS Hosting from AlexHost β optimized for performance-critical monitoring workloads.
Table of Contents
- Update System Packages
- Install Grafana via the Official APT Repository
- Start and Enable the Grafana Service
- Access the Grafana Web Interface
- Configure Data Sources
- Create Your First Dashboard
- Set Up Alerts
- Secure Grafana with HTTPS and Access Controls
- Manage and Update Grafana
Step 1: Update System Packages {#step-1}
Before installing any new software, it's critical to synchronize your package index and apply all available upgrades. This ensures compatibility and reduces the risk of dependency conflicts.
sudo apt update && sudo apt upgrade -yAllow the process to complete before proceeding. On a freshly provisioned server, this may take a few minutes.
Step 2: Install Grafana via the Official APT Repository {#step-2}
Grafana maintains an official APT repository for Debian-based systems, including Ubuntu. Using the official repository ensures you always have access to the latest stable releases and security patches.
Step 2a: Install Required Dependencies
First, install the software-properties-common package, which provides the add-apt-repository utility:
sudo apt install -y software-properties-common apt-transport-https wget gnupg2Step 2b: Import the Grafana GPG Signing Key
Adding the GPG key allows your system to verify the authenticity of packages downloaded from the Grafana repository:
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -Step 2c: Add the Official Grafana APT Repository
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"Step 2d: Update the Package List and Install Grafana
sudo apt update
sudo apt install grafana -yOnce the installation completes, verify the installed version:
grafana-server -vStep 3: Start and Enable the Grafana Service {#step-3}
After installation, start the Grafana server daemon and configure it to launch automatically on system boot:
sudo systemctl start grafana-server
sudo systemctl enable grafana-serverVerify that the service is running correctly:
sudo systemctl status grafana-serverYou should see output similar to the following, confirming the service is active (running):
β grafana-server.service - Grafana instance
Loaded: loaded (/lib/systemd/system/grafana-server.service; enabled)
Active: active (running) since ...If the service fails to start, check the logs for errors:
sudo journalctl -u grafana-server -fStep 4: Access the Grafana Web Interface {#step-4}
By default, Grafana listens on port 3000. Open your web browser and navigate to:
http://your_server_ip:3000Replace your_server_ip with the actual IP address or hostname of your server.
Default Login Credentials
| Field | Value |
|---|---|
| Username | admin |
| Password | admin |
Upon your first login, Grafana will immediately prompt you to set a new, secure password. Do not skip this step β leaving the default credentials in place is a significant security risk.
> Firewall Note: If you're running UFW or another firewall, open port 3000 to allow browser access:
> β`bash
> sudo ufw allow 3000/tcp
> sudo ufw reload
> β`
Step 5: Configure Data Sources {#step-5}
Grafana is a visualization layer β it doesn't store metrics itself. Instead, it connects to external data sources such as Prometheus, InfluxDB, Elasticsearch, MySQL, PostgreSQL, and many others. Configuring a data source is the essential first step before you can build any dashboard.
Step 5a: Navigate to Data Sources
- In the left sidebar, click the gear icon (β) to open the Configuration menu.
- Select Data Sources.
Step 5b: Add a New Data Source
- Click Add data source.
- Browse the list and select your desired data source type (e.g., Prometheus, InfluxDB, MySQL).
Step 5c: Enter Connection Details
Fill in the connection parameters for your chosen data source. For example, if you're connecting to a Prometheus instance running locally:
- URL:
http://localhost:9090 - Access:
Server (default) - Scrape interval:
15s(match your Prometheus scrape config)
For a remote InfluxDB instance, you would provide the host URL, database name, and authentication credentials.
Step 5d: Save and Test the Connection
Click Save & Test. Grafana will attempt to connect to the data source and display a success or error message. A green "Data source is working" confirmation means you're ready to build dashboards.
Step 6: Create Your First Grafana Dashboard {#step-6}
With a data source connected, you can now create dashboards to visualize your metrics in real time.
Step 6a: Create a New Dashboard
- In the left sidebar, click the + (plus) icon.
- Select Dashboard.
- Click Add new panel.
Step 6b: Configure the Panel
The panel editor opens, giving you full control over what data is displayed and how it's visualized.
- Data Source: Select the data source you configured in Step 5.
- Query: Write your metric query. For Prometheus, use PromQL. For example, to visualize CPU usage:
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)- Visualization Type: Choose from Time series, Gauge, Bar chart, Table, Stat, Heatmap, and more β depending on the nature of your data.
- Panel Title: Give your panel a descriptive name (e.g., "CPU Usage β Last 1 Hour").
Step 6c: Customize and Save
Use the right-hand panel options to configure thresholds, color schemes, axis labels, and legends. Once satisfied:
- Click Apply to add the panel to your dashboard.
- Repeat the process to add multiple panels β each tracking a different metric.
- Click the Save dashboard icon (floppy disk) in the top-right corner, give your dashboard a name, and click Save.
> Pro Tip: Grafana's official dashboard library offers hundreds of pre-built, community-contributed dashboards for popular stacks like Node Exporter, Kubernetes, MySQL, and NGINX. You can import them directly using a dashboard ID.
Step 7: Set Up Alerts {#step-7}
Grafana's built-in alerting engine allows you to define threshold-based rules and receive notifications when metrics breach critical levels β keeping you informed before small issues become major outages.
Step 7a: Create an Alert Rule
- Open the panel you want to monitor and click Edit.
- Navigate to the Alert tab within the panel editor.
- Click Create Alert.
Step 7b: Define Alert Conditions
Configure the conditions that trigger the alert. For example:
- Condition:
WHEN avg() OF query(A, 5m, now) IS ABOVE 90 - This triggers an alert when the average value of your metric exceeds 90 over the last 5 minutes.
Set the Evaluate every and For fields to control how frequently the rule is evaluated and how long the condition must persist before firing.
Step 7c: Configure Notification Channels
- Go to Alerting β Notification channels in the left sidebar.
- Click Add channel and choose your preferred method:
- Email β requires SMTP configuration in
grafana.ini - Slack β requires a Slack webhook URL
- PagerDuty, OpsGenie, Webhook, and more
Assign the notification channel to your alert rule so that the right people are notified when thresholds are exceeded.
Step 8: Secure Grafana with HTTPS and Access Controls {#step-8}
Running Grafana in a production environment without proper security hardening is a serious risk. Follow these best practices to protect your monitoring infrastructure.
8a: Enable HTTPS with an SSL Certificate
Encrypting traffic to your Grafana instance is essential, especially if it's accessible over the public internet. You'll need a valid SSL certificate β AlexHost offers affordable SSL Certificates that are easy to deploy.
Once you have your certificate and private key, edit the Grafana configuration file:
sudo nano /etc/grafana/grafana.iniLocate the [server] section and update the following parameters:
[server]
protocol = https
http_port = 3000
cert_file = /etc/grafana/ssl/grafana.crt
cert_key = /etc/grafana/ssl/grafana.keySave the file and restart Grafana:
sudo systemctl restart grafana-serverGrafana will now be accessible over HTTPS on port 3000.
> Recommended Alternative: Place Grafana behind a reverse proxy (e.g., Nginx or Apache) and terminate SSL at the proxy level. This is a more flexible and widely adopted approach in production environments.
8b: Restrict Admin Access and Manage Users
- Navigate to Server Admin β Users in the Grafana UI.
- Review and adjust user roles:
- Admin β full access
- Editor β can create and edit dashboards
- Viewer β read-only access
- Disable or delete unused accounts.
- Consider enabling LDAP or OAuth (Google, GitHub, GitLab) for centralized authentication.
8c: Additional Hardening Recommendations
- Disable anonymous access in
grafana.ini:
[auth.anonymous]
enabled = false- Change the default HTTP port if Grafana is exposed publicly.
- Restrict outbound connections from the Grafana server using firewall rules.
- Enable audit logging to track user activity.
Step 9: Manage and Update Grafana {#step-9}
Keeping Grafana up to date is critical for security and access to new features. Because you installed Grafana from the official APT repository, updates are straightforward.
Update Grafana
sudo apt update
sudo apt upgrade grafana -yCommon Service Management Commands
| Action | Command |
|---|---|
| Start Grafana | sudo systemctl start grafana-server |
| Stop Grafana | sudo systemctl stop grafana-server |
| Restart Grafana | sudo systemctl restart grafana-server |
| Reload config | sudo systemctl reload grafana-server |
| Check status | sudo systemctl status grafana-server |
| View logs | sudo journalctl -u grafana-server -f |
Backup Grafana Data
Grafana stores its configuration, dashboards, and user data in a SQLite database by default, located at:
/var/lib/grafana/grafana.dbBack up this file regularly, especially before performing upgrades:
sudo cp /var/lib/grafana/grafana.db /var/lib/grafana/grafana.db.backup-$(date +%F)For larger deployments, consider migrating to a dedicated MySQL or PostgreSQL backend for improved reliability and easier backup management.
Troubleshooting Common Issues
| Problem | Likely Cause | Solution |
|---|---|---|
| Cannot access port 3000 | Firewall blocking the port | Run sudo ufw allow 3000/tcp |
| Service fails to start | Configuration error or port conflict | Check journalctl -u grafana-server |
| "Data source connection failed" | Wrong URL or firewall rules | Verify the data source URL and network access |
| Login not working after password change | Browser cache | Clear cache or use incognito mode |
| Grafana running slowly | Insufficient server resources | Upgrade to a higher-tier VPS Hosting plan |
Choosing the Right Hosting for Your Grafana Stack
The performance of your Grafana deployment depends heavily on the underlying infrastructure. Here's a quick guide to choosing the right hosting tier:
- Small teams / personal projects: Shared Web Hosting can work for lightweight setups, though a VPS is generally recommended for Grafana.
- Production monitoring stacks: A VPS Hosting plan gives you dedicated resources, root access, and the flexibility to run Grafana alongside Prometheus, InfluxDB, or other components.
- High-volume data ingestion / ML-driven observability: Consider GPU Hosting for workloads that involve large-scale data processing or AI-powered anomaly detection.
- Enterprise-grade deployments: Dedicated Servers provide maximum performance, isolation, and security for mission-critical monitoring infrastructure.
Conclusion
Installing and configuring Grafana on Ubuntu is a straightforward process that unlocks powerful, real-time visibility into your systems and applications. By following this guide, you've learned how to:
- Install Grafana from the official repository on Ubuntu
- Start, enable, and verify the Grafana service
- Connect data sources such as Prometheus, InfluxDB, and MySQL
- Build interactive dashboards with custom panels and visualizations
- Configure threshold-based alerts with multi-channel notifications
- Secure your Grafana instance with HTTPS and role-based access controls
- Maintain and update Grafana using standard APT commands
Whether you're monitoring a single VPS or a complex multi-node infrastructure, Grafana provides the observability foundation you need to stay ahead of performance issues and make data-driven decisions. Pair it with a reliable hosting environment from AlexHost, and you have everything you need to build a world-class monitoring stack.
