How to install Prometheus on Ubuntu

Ankita LunawatAnkita Lunawat
2 min read

Update Your System

Ensure your system is up to date.

sudo apt update

Create a Prometheus User

For security reasons, create a separate user to run Prometheus.

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

Create Directories for Prometheus

Create directories to store Prometheus binaries and configuration files.

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

Download Prometheus

Download the latest version of Prometheus from the official website.

curl -LO https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz

Extract the Prometheus Archive

Extract the downloaded tarball and move the files to the appropriate locations.

tar -xvf prometheus-2.48.1.linux-amd64.tar.gz
cd prometheus-2.48.1.linux-amd64

sudo mv prometheus /usr/local/bin/
sudo mv promtool /usr/local/bin/

sudo mv consoles /etc/prometheus
sudo mv console_libraries /etc/prometheus
sudo mv prometheus.yml /etc/prometheus/

Set Ownership

Set the ownership for the Prometheus directories.

sudo chown -R prometheus:prometheus /etc/prometheus
sudo chown -R prometheus:prometheus /var/lib/prometheus

Create a Systemd Service File

Create a systemd service file to manage the Prometheus service.

sudo vi /etc/systemd/system/prometheus.service

Add the following code to the file:

iniCopy code[Unit]
Description=Prometheus
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

[Install]
WantedBy=multi-user.target

Start and Enable Prometheus

Reload systemd to recognize the Prometheus service and then start and enable the service.

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

Verify Prometheus is Running

Check the status of the Prometheus service to ensure it's running correctly.

sudo systemctl status prometheus

Access Prometheus Web Interface

Prometheus should now be running and accessible via its web interface.http://<your-server-ip>:9090.

You can now start monitoring your applications using Prometheus.

0
Subscribe to my newsletter

Read articles from Ankita Lunawat directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ankita Lunawat
Ankita Lunawat

I am a dedicated and experienced Cloud Engineer with two years in the industry, specializing in designing, implementing, and managing scalable and secure cloud infrastructures. With a strong foundation in AWS, Azure, and GCP, I excel at leveraging cloud services to optimize performance, enhance security, and reduce operational costs. My expertise includes automated deployment pipelines, infrastructure as code (IaC) with tools like Terraform and container orchestration using Kubernetes and Docker. Throughout my career, I've collaborated with cross-functional teams to deliver robust cloud solutions, ensuring high availability and fault tolerance. I'm passionate about staying at the forefront of cloud technology trends and continuously enhancing my skill set to provide innovative solutions that drive business success. Whether it's migrating legacy systems to the cloud or architecting new cloud-native applications, I bring a strategic approach to every project, focusing on efficiency, scalability, and reliability. In addition to my technical skills, I am an advocate for DevOps practices, promoting a culture of collaboration and continuous improvement within development and operations teams. My commitment to learning and adapting to new technologies ensures that I can meet the evolving needs of any organization and deliver top-tier cloud solutions.