How To Install Prometheus On Ubuntu

How To Install Prometheus On Ubuntu

Reading time1 min
#Monitoring#Linux#DevOps#Prometheus#Ubuntu#NodeExporter

Step-by-Step Guide to Installing Prometheus on Ubuntu for Robust Monitoring

Most guides stop at basic installation, but this post dives deeper into optimizing Prometheus setup on Ubuntu to leverage its full potential from day one—your infrastructure deserves more than a vanilla install.

Prometheus has become the de facto open-source monitoring solution for modern infrastructure. Its powerful time-series database, flexible querying language, and native alerting mechanisms make it indispensable for maintaining system reliability and performance. But installing Prometheus correctly on Ubuntu is the first crucial step toward building a scalable, proactive monitoring stack.

In this detailed guide, I’ll walk you through every step to get Prometheus up and running on an Ubuntu server, alongside tips to optimize your setup for real-world usage. Let’s get started!


Why Choose Prometheus?

Before jumping into installation, here’s a quick refresher: Prometheus excels at collecting metrics from your applications and servers and storing them efficiently. Unlike traditional monitoring tools, it pulls data via HTTP endpoints (called exporters), and comes with a powerful query language (PromQL) that lets you slice and dice your data in countless ways.

This means better visibility into system health and the ability to create custom alerts based on meaningful thresholds.


Prerequisites

  • A fresh or existing Ubuntu 20.04/22.04 server with sudo privileges
  • Basic familiarity with Linux terminal commands
  • Open ports 9090 (default Prometheus web UI) accessible if remote access is needed

Step 1: Create a Dedicated Prometheus User

For security reasons, don’t run Prometheus as root. Instead, create a system user with no login access:

sudo useradd --no-create-home --shell /bin/false prometheus

This user will own all Prometheus files and processes.


Step 2: Download the Latest Prometheus Release

Go to Prometheus' GitHub releases page to identify the latest stable version or grab it directly via wget:

cd /tmp
curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64.tar.gz | cut -d '"' -f 4 | wget -i -

Alternatively, specify version explicitly:

wget https://github.com/prometheus/prometheus/releases/download/v2.44.0/prometheus-2.44.0.linux-amd64.tar.gz

Extract the archive:

tar xvf prometheus-*.tar.gz

Step 3: Install Binaries and Configure Directory Structure

Move binaries to /usr/local/bin:

sudo cp prometheus-*/prometheus /usr/local/bin/
sudo cp prometheus-*/promtool /usr/local/bin/

Create directories for config and data storage:

sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus

Copy console libraries used by Prometheus UI:

sudo cp -r prometheus-*/consoles /etc/prometheus/
sudo cp -r prometheus-*/console_libraries /etc/prometheus/

Set ownership:

sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool

Step 4: Create the Default Configuration File (prometheus.yml)

At minimum, you need a scrape configuration telling Prometheus where to pull metrics from — even if just itself initially.

Create /etc/prometheus/prometheus.yml:

global:
  scrape_interval: 15s  # How often to scrape targets by default

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

This configuration means Prometheus monitors itself.

Adjust scrape_interval based on your environment—lower intervals gather metrics more frequently but increase server load.


Step 5: Setup Systemd Service for Easy Management

Create /etc/systemd/system/prometheus.service file with the following content:

[Unit]
Description=Prometheus Monitoring Server
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple

ExecStart=/usr/local/bin/prometheus \
    --config.file=/etc/prometheus/prometheus.yml \
    --storage.tsdb.path=/var/lib/prometheus/ \
    --web.console.templates=/etc/prometheus/consoles \
    --web.console.libraries=/etc/prometheus/console_libraries

Restart=on-failure

[Install]
WantedBy=multi-user.target

Reload systemd daemon and start Prometheus:

sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus

Check status:

sudo systemctl status prometheus

Step 6: Verify Installation & Access Web UI

Open your browser on http://your_server_ip_or_domain:9090 — you should see the official Prometheus dashboard with “Status > Targets” page listing active scrape targets (right now just itself).

Try running a simple query like up, which returns whether each target is up (1) or down (0).


Optional but Recommended: Install Node Exporter for System Metrics

Prometheus alone doesn’t collect OS-level metrics without exporters.

Install Node Exporter on the same Ubuntu server:

  1. Download latest release from node_exporter releases.
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz 
tar xvf node_exporter-*.tar.gz 
cd node_exporter-*
sudo cp node_exporter /usr/local/bin/
  1. Create node_exporter user:
sudo useradd --no-create-home --shell /bin/false node_exporter 
  1. Assign ownership of binary:
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter 
  1. Create systemd service file /etc/systemd/system/node_exporter.service:
[Unit]
Description=Node Exporter Service for hardware metrics collection                         
Wants=network-online.target                                     
After=network-online.target           

[Service]                        
User=node_exporter                   
Group=node_exporter               
Type=simple                        
ExecStart=/usr/local/bin/node_exporter                   
Restart=on-failure       

[Install]                   
WantedBy=multi-user.target           
  1. Start and enable node exporter service:
sudo systemctl daemon-reload                               sudo systemctl start node_exporter                               sudo systemctl enable node_exporter                               sudo systemctl status node_exporter  
  1. Update /etc/prometheus/prometheus.yml to add this new target under scrape_configs:
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100']

Reload Prometheus config by restarting service:

sudo systemctl restart prometheus  

Now you’ll start seeing OS-level metrics like CPU usage, memory stats, disk I/O, etc.


Wrapping Up & Next Steps

You’ve now installed a solid-promises base monitoring stack on Ubuntu featuring both Prometheus server and Node Exporter collecting local host metrics out of the box.

From here you can…

  • Add exporters for databases (MySQL, PostgreSQL), web servers (Apache, NGINX), container runtimes (Docker, Kubernetes)
  • Set up Alertmanager alongside PromQL-based alert rules to notify your team in case of issues
  • Integrate Grafana with PromQL queries for beautiful dashboards
  • Fine-tune retention policies and storage settings based on infrastructure scale

Properly installing and configuring these components lays the foundation for observability that scales over time — no more blind spots in your systems.

If you found this guide helpful or want me to cover advanced topics like alerting rules or Grafana integration next, let me know in the comments!

Happy monitoring!