To run Prometheus as a service, create a systemd unit file at /etc/systemd/system/prometheus.service that points to the binary by its absolute path, then reload systemd and enable the unit so it starts at boot and restarts after a crash. This page explains the two unit files in the example above, gives a corrected and hardened version, and adds the missing setup, verification and troubleshooting steps.
Step 1 – Create a file:
$ vi /etc/systemd/system/prometheus.service
Step 2 – Reload the Systemctl Daemon:
$ sudo systemctl daemon-reload
Step 3 – Start the Prometheus service:
$ sudo systemctl start prometheus
$ sudo systemctl status prometheus
What the unit file does
A systemd unit file tells the init system how to run a long-lived process. For Prometheus, the three sections in the example above do the following:
- [Unit] holds the description and the startup order.
After=network-online.targettogether withWants=network-online.targetmakes Prometheus wait until the network is up.After=alone sets the order but doesn't pull the network target in. - [Service] says which user runs the process, the exact command line (
ExecStart) and the restart policy. - [Install] controls what
systemctl enabledoes.WantedBy=multi-user.targetstarts the service at a normal multi-user boot.
The second unit file in the example above is the better starting point. It runs Prometheus as a dedicated unprivileged user, uses absolute paths and passes an explicit config file. The first one has several problems, listed in the corrections section below.
Prerequisites: binary, user and directories
The unit file expects the binary, the config and the data directory to exist already, owned by the right user. The example above skips this part. On a typical Linux host, run:
# 1. Create a system user with no login shell and no home directory
sudo useradd --system --no-create-home --shell /usr/sbin/nologin prometheus
# 2. Create config and data directories
sudo mkdir -p /etc/prometheus /var/lib/prometheus
# 3. Download and unpack a release (set VERSION to the current release)
VERSION="<x.y.z>"
cd /tmp
curl -LO https://github.com/prometheus/prometheus/releases/download/v${VERSION}/prometheus-${VERSION}.linux-amd64.tar.gz
tar xzf prometheus-${VERSION}.linux-amd64.tar.gz
cd prometheus-${VERSION}.linux-amd64
# 4. Install binaries and the sample config
sudo cp prometheus promtool /usr/local/bin/
sudo cp prometheus.yml /etc/prometheus/
# 5. Set ownership
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus
# 6. Validate the config before starting
promtool check config /etc/prometheus/prometheus.ymlCode language: PHP (php)
The last command should report SUCCESS for the config file. For a full walkthrough that also installs Node Exporter, see Install and Configure Prometheus Server and Node Exporter in Linux.
A corrected, production-ready unit file
Writing to /etc/systemd/system needs root, so open the file with sudo vi /etc/systemd/system/prometheus.service or sudo systemctl edit --force --full prometheus.service. Then paste:
[Unit]
Description=Prometheus monitoring server
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus/ \
--storage.tsdb.retention.time=15d \
--web.listen-address=0.0.0.0:9090
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5s
LimitNOFILE=65536
# Hardening
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
ReadWritePaths=/var/lib/prometheus
[Install]
WantedBy=multi-user.targetCode language: PHP (php)
ExecStartuses absolute paths only. Systemd does not expand~or shell variables the way a login shell does.--config.fileis needed. Without it, Prometheus looks forprometheus.ymlin its working directory, which is/for a system service.--storage.tsdb.pathis where the time series database lives. The service user must be able to write to it.--storage.tsdb.retention.timesets how long samples are kept. 15 days is the default. Set it to match your disk capacity.ExecReloadmakessystemctl reload prometheussend SIGHUP. That reloads the config without restarting the process or losing in-memory data.LimitNOFILEraises the open-file limit. A TSDB with many series and scrape targets can exceed the default.ProtectSystem=strictmakes the whole filesystem read-only for the service.ReadWritePathsthen gives back write access to the data directory only.
Note: If you need --web.external-url (for example behind a reverse proxy), set it to the real public URL. A placeholder such as http://myurl.com:9090 breaks links in the UI and in alert notifications.
Enable, start and verify
sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
sudo systemctl status prometheus
enable --now starts the service immediately and also sets it to start at boot. The steps above only run start, so Prometheus would not come back after a reboot. A healthy status output includes a line like:
Active: active (running) since ...Code language: HTTP (http)
Then check the HTTP endpoints and logs:
curl http://localhost:9090/-/healthy
curl http://localhost:9090/-/ready
journalctl -u prometheus -fCode language: JavaScript (javascript)
The health endpoint returns a short text message saying the server is healthy. Open http://<server-ip>:9090/targets in a browser to confirm the targets are UP. To reach the UI from another machine, open port 9090 in the host firewall, for example sudo ufw allow 9090/tcp or sudo firewall-cmd --add-port=9090/tcp --permanent && sudo firewall-cmd --reload.
Day-to-day operations
| Task | Command |
|---|---|
| Reload config after editing prometheus.yml | promtool check config /etc/prometheus/prometheus.yml && sudo systemctl reload prometheus |
| Restart after changing flags in the unit file | sudo systemctl daemon-reload && sudo systemctl restart prometheus |
| Stop the service | sudo systemctl stop prometheus |
| Disable start at boot | sudo systemctl disable prometheus |
| View recent logs | journalctl -u prometheus --since "1 hour ago" |
| Override settings without editing the main file | sudo systemctl edit prometheus |
Note: Always run promtool check config before a reload. If the new config is invalid, Prometheus keeps the old one and logs an error, so a broken edit can go unnoticed.
Common errors and fixes
| Symptom in systemctl status or journalctl | Cause | Fix |
|---|---|---|
| Unit fails to load with a message about the executable path not being absolute | ExecStart uses ~ or a relative path | Use the full path, e.g. /usr/local/bin/prometheus |
status=203/EXEC | Binary missing, wrong path or not executable | Check with ls -l /usr/local/bin/prometheus and chmod +x if needed |
status=217/USER | The User= account does not exist | Create it with useradd --system as shown above |
opening storage failed / permission denied | Data directory not writable by the service user | sudo chown -R prometheus:prometheus /var/lib/prometheus |
Error loading config / couldn't load configuration | YAML syntax error or wrong config path | Run promtool check config and check --config.file |
address already in use | Another process is using port 9090 | Find it with sudo ss -ltnp | grep 9090, then stop it or change --web.listen-address |
| Changes to the unit file have no effect | systemd still has the old definition loaded | Run sudo systemctl daemon-reload before restarting |
Corrections to the original
- Tilde in ExecStart. The first unit file uses
ExecStart=~/prometheus/prometheus. Systemd needs an absolute path to the executable. Install the binary to a fixed location such as/usr/local/binand point to it there. - Running as root. The first unit file sets
User=root. Prometheus doesn't need root privileges. Use a dedicatedprometheussystem user. - Missing config flag. The first unit file doesn't pass
--config.file, so Prometheus looks forprometheus.ymlin/and fails. Pass the config path explicitly. - Missing Wants= line. The first unit file has
After=network-online.targetwithoutWants=network-online.target, so the network target may not be pulled in at all. - Console flags on Prometheus 3.x. The second unit file points
--web.console.templatesand--web.console.librariesat directories that Prometheus 3.x release archives no longer include. Remove these flags unless you have your own console templates in place. - Missing sudo. The file is created without
sudo, but writing to/etc/systemd/systemneeds root. - Not enabled at boot. The steps never run
systemctl enable, so the service would not start after a reboot. - Wrong file extension. The gist files are named
.sh, but they are systemd unit files, not shell scripts. Save the file asprometheus.service.
For more on the Prometheus server itself, see the Prometheus tutorials or start writing queries with the PromQL Node Exporter examples.
Frequently asked questions
Where should the Prometheus systemd service file be placed?
Put custom unit files in /etc/systemd/system/prometheus.service. Files under /lib/systemd/system or /usr/lib/systemd/system belong to distribution packages and can be overwritten on upgrade.
Why does Prometheus fail to start with status=203/EXEC?
Systemd could not run the binary named in ExecStart. Usually the path is wrong, relative or uses ~, or the file isn't executable. Use an absolute path such as /usr/local/bin/prometheus and check its permissions.
How do I reload the Prometheus configuration without restarting?
Add ExecReload=/bin/kill -HUP $MAINPID to the unit file and run sudo systemctl reload prometheus. You can also start Prometheus with --web.enable-lifecycle and send curl -X POST http://localhost:9090/-/reload, but only if the endpoint is not exposed to untrusted networks.
Should Prometheus run as root?
No. Prometheus only needs to read its config and write to its data directory. Run it as a dedicated system user with no login shell, and limit filesystem access with options such as ProtectSystem=strict and ReadWritePaths.
How do I make Prometheus start automatically after a reboot?
Run sudo systemctl enable prometheus, or sudo systemctl enable --now prometheus to also start it right away. This links the unit into multi-user.target through its WantedBy= setting.
Related tutorials
- Install and Configure Prometheus Server and Node Exporter in Linux
- More Prometheus tutorials
- Prometheus PromQL Example Query: node exporter
- What is Prometheus and use cases of Prometheus?
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals