How to install Prometheus on Ubuntu

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.
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
Hi there! I'm a passionate AWS DevOps Engineer with 2+ years of experience in building and managing scalable, reliable, and secure cloud infrastructure. I'm excited to share my knowledge and insights through this blog. Here, you'll find articles on: AWS Services: Deep dives into core AWS services like EC2, S3, Lambda, and more. DevOps Practices: Best practices for CI/CD, infrastructure as code, and automation. Security: Tips and tricks for securing your AWS environments. Serverless Computing: Building and deploying serverless applications. Troubleshooting: Common issues and solutions in AWS. I'm always eager to learn and grow, and I hope this blog can be a valuable resource for fellow DevOps enthusiasts. Feel free to connect with me on [LinkedIn/Twitter] or leave a comment below!