
Master Your Monitoring: A Complete Guide to Installing Prometheus on Ubuntu
In today’s complex IT environments, robust monitoring isn’t a luxury—it’s a necessity. Gaining deep visibility into your systems’ performance is crucial for maintaining reliability, troubleshooting issues, and making informed decisions. Prometheus, a leading open-source monitoring and alerting toolkit, has become the industry standard for collecting and analyzing time-series data.
This comprehensive guide will walk you through every step of installing and configuring Prometheus on an Ubuntu server. By following these instructions, you will have a powerful, production-ready monitoring foundation for your infrastructure.
Prerequisites
Before we begin, ensure you have the following:
- An Ubuntu server (this guide is tested on 22.04 LTS but should work on other recent versions).
- A non-root user with
sudoprivileges.
Step 1: Update Your System
First, it’s always a best practice to update your server’s package index and upgrade existing packages to their latest versions. This ensures a clean and secure starting point.
Open your terminal and run the following commands:
sudo apt update
sudo apt upgrade -y
Step 2: Create a Dedicated Prometheus User
For security purposes, Prometheus should not run as the root user. We will create a dedicated system user and group specifically for the Prometheus service. This follows the principle of least privilege, limiting the service’s access to only what it needs.
Create a prometheus group:
sudo groupadd --system prometheus
Now, create the prometheus system user, add it to the group, and set its shell to /bin/false so it cannot be used for a direct login:
sudo useradd -s /bin/false -r -g prometheus prometheus
Step 3: Download and Install Prometheus
Prometheus is distributed as a pre-compiled binary. We’ll download the latest stable release directly from the official website.
Navigate to the
/tmpdirectory, which is a good place for temporary downloads.cd /tmpVisit the official Prometheus downloads page to find the URL for the latest stable version for Linux (
linux-amd64). Copy the link address and usewgetto download it.wget https://github.com/prometheus/prometheus/releases/download/v2.53.0/prometheus-2.53.0.linux-amd64.tar.gz(Note: Check the downloads page for the absolute latest version and update the URL accordingly.)
Once the download is complete, extract the archive:
tar xvf prometheus-*.linux-amd64.tar.gzThis creates a directory named something like
prometheus-2.53.0.linux-amd64. Now, we’ll move the essential binary files,prometheusandpromtool, to/usr/local/bin, a standard location for user-installed executables.cd prometheus-*.linux-amd64 sudo mv prometheus /usr/local/bin/ sudo mv promtool /usr/local/bin/
Step 4: Configure Prometheus Directories and Files
Prometheus needs a directory for its configuration files and another for its data.
First, create the main configuration directory at
/etc/prometheus.sudo mkdir /etc/prometheusNext, move the
consolesandconsole_librariesdirectories, along with the main configuration fileprometheus.yml, into this new directory.sudo mv consoles /etc/prometheus sudo mv console_libraries /etc/prometheus sudo mv prometheus.yml /etc/prometheusCrucially, we must set the correct ownership for these files and directories to the
prometheususer we created earlier.sudo chown -R prometheus:prometheus /etc/prometheus/ sudo chown prometheus:prometheus /usr/local/bin/prometheus sudo chown prometheus:prometheus /usr/local/bin/promtoolFinally, create the data directory where Prometheus will store its time-series database and set its ownership.
sudo mkdir /var/lib/prometheus sudo chown prometheus:prometheus /var/lib/prometheus/
Step 5: Create the systemd Service File
To manage Prometheus as a standard system service (allowing it to start on boot, restart automatically, etc.), we need to create a systemd unit file.
Create a new service file using a text editor like
nano:sudo nano /etc/systemd/system/prometheus.servicePaste the following configuration into the file. This tells
systemdhow to run, manage, and secure the Prometheus process.[Unit] Description=Prometheus Time Series Collection and Processing 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 [Install] WantedBy=multi-user.targetUserandGroup: Specifies that the service runs as our dedicatedprometheususer.ExecStart: Defines the command to start Prometheus, pointing to our configuration file and data directory.
Save the file and exit the editor (in
nano, pressCTRL+X, thenY, thenEnter).
Step 6: Start and Enable the Prometheus Service
Now that our service is defined, we can start it and enable it to launch automatically on system boot.
Reload the
systemddaemon to make it aware of the new service file.sudo systemctl daemon-reloadStart the Prometheus service.
sudo systemctl start prometheusEnable the service to start on boot.
sudo systemctl enable prometheusFinally, check the status to ensure it’s running correctly.
sudo systemctl status prometheusYou should see an output indicating the service is active (running). If not, review the previous steps for any errors.
Step 7: Verify Installation and Configure the Firewall
Prometheus exposes a web interface on port 9090. You can access it from your browser, but first, you may need to allow traffic through your firewall.
If you are using UFW (Uncomplicated Firewall), allow access to port 9090:
sudo ufw allow 9090/tcpNow, open your web browser and navigate to your server’s IP address followed by the port number:
http://your_server_ip:9090
You should see the Prometheus web UI. From here, you can explore metrics, view service discovery status, and build queries using PromQL.
Next Steps
Congratulations! You have successfully installed and configured a running instance of Prometheus on your Ubuntu server. This is the first step in building a powerful observability stack.
Your next steps should include:
- Configuring Targets: Edit the
/etc/prometheus/prometheus.ymlfile to add more services and endpoints for Prometheus to scrape metrics from. - Installing Exporters: Deploy exporters like the Node Exporter to gather detailed system metrics from your servers.
- Visualizing Data: Integrate Prometheus with a visualization tool like Grafana to create beautiful, insightful dashboards.
Source: https://kifarunix.com/install-prometheus-on-ubuntu-18-04/


