Install Nagios Core on Ubuntu
This guide installs Nagios Core 4.5.14 from source on Ubuntu 26.04 LTS (Resolute Raccoon).
Everything goes to /opt/nagios. To remove Nagios later, delete that directory
and the systemd unit. All commands run as root, or via sudo.
Prepare your system
addgroup --system nagios
adduser --system nagios
adduser nagios nagiosInstall dependencies
apt-get update
apt-get install build-essential libgd-dev libpng-dev libssl-dev unziplibssl-dev is not optional: configure stops with Cannot find ssl headers
without it. Neither is unzip — the build unpacks the bundled web assets with
it and aborts on Cannot continue without unzip!.
Download and install Nagios Core
cd /tmp/
wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.5.14.tar.gz
tar xfv nagios-4.5.14.tar.gz
cd nagioscore-nagios-4.5.14/
./configure --prefix=/opt/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install
make install-commandmode
make install-config
make install-develconfigure prints a summary before it finishes. The line that matters for
Statusengine is the event broker:
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagios
Event Broker: yes
Install ${prefix}: /opt/nagios
Install ${includedir}: /opt/nagios/include/nagios
Lock file: /run/nagios.lock
Check result directory: /opt/nagios/var/spool/checkresults
make install-devel is the step that puts the Nagios headers in
/opt/nagios/include/nagios/. The broker module includes them as
<nagios/nagios.h>, so without this target there is nothing to build it
against later.
Start Nagios Core through systemd
Pitfall! If you are going to use Nagios with the
Statusengine broker module
, the Gearman Job Server has to
be running before Nagios starts, so systemd needs to know about the
dependency. Replace the After= line below with:
After=network.target local-fs.target gearman-job-server.serviceIf you have not installed it yet:
apt-get install gearman-job-serverPut the following in /etc/systemd/system/nagios.service:
[Unit]
Description=Nagios Core
Documentation=https://www.nagios.org/documentation
After=network.target local-fs.target
[Service]
Type=forking
PIDFile=/run/nagios.lock
ExecStartPre=/opt/nagios/bin/nagios -v /opt/nagios/etc/nagios.cfg
ExecStart=/opt/nagios/bin/nagios -d /opt/nagios/etc/nagios.cfg
ExecStop=/bin/kill -s TERM ${MAINPID}
ExecStopPost=/bin/rm -f /opt/nagios/var/rw/nagios.cmd
ExecReload=/bin/kill -s HUP ${MAINPID}
[Install]
WantedBy=multi-user.targetThere is deliberately no User=nagios here, unlike the Naemon unit. Nagios
writes its lock file to /run/nagios.lock, which only root may create; the
daemon then drops to the nagios_user from nagios.cfg on its own, so the
process you end up with runs as nagios either way.
PIDFile= points at that same lock file. Without it systemd has to guess which
of the forked processes is the main one.
systemctl daemon-reload
systemctl start nagiosCheck that it came up with systemctl status nagios:
● nagios.service - Nagios Core
Loaded: loaded (/etc/systemd/system/nagios.service; disabled; preset: enabled)
Active: active (running)
Docs: https://www.nagios.org/documentation
Process: 127 ExecStartPre=/opt/nagios/bin/nagios -v /opt/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
Process: 129 ExecStart=/opt/nagios/bin/nagios -d /opt/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
Main PID: 130 (nagios)
Tasks: 26
Memory: 25.3M
CGroup: /system.slice/nagios.service
├─130 /opt/nagios/bin/nagios -d /opt/nagios/etc/nagios.cfg
├─133 /opt/nagios/bin/nagios --worker /opt/nagios/var/rw/nagios.qh
├─134 /opt/nagios/bin/nagios --worker /opt/nagios/var/rw/nagios.qh
└─...
The line to look for in the pre-flight check is
Things look okay - No serious problems were detected.
To start Nagios on boot:
systemctl enable nagios.serviceInstall monitoring plugins
Nagios installs a sample configuration with some basic checks, so you need the
plugins for those checks to work. Unlike Naemon, Nagios does not look in
/usr/lib/nagios/plugins by default, so resource.cfg has to point at it:
apt-get install monitoring-plugins
echo '$USER1$=/usr/lib/nagios/plugins' > /opt/nagios/etc/resource.cfg
systemctl restart nagiosThe sample localhost host should go green within a minute. To confirm without
a web interface, look at the status file:
# grep -A30 "hoststatus {" /opt/nagios/var/status.dat | grep -E "host_name|current_state|plugin_output"
host_name=localhost
current_state=0
plugin_output=PING OK - Packet loss = 0%, RTA = 0.04 ms
Congratulations, you have installed Nagios Core.
-Dnagios=true -Dnagios_include_dir=/opt/nagios/include — the headers
make install-devel put there above.Running Nagios in the foreground
For debugging it can be useful to run Nagios in the foreground instead. Exit with Ctrl+C.
root@ubuntu:/opt/nagios# sudo -u nagios /bin/bash
nagios@ubuntu:/opt/nagios$ /opt/nagios/bin/nagios /opt/nagios/etc/nagios.cfg
Nagios Core 4.5.14
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2026-08-05
License: GPL
Website: https://www.nagios.org
Nagios 4.5.14 starting... (PID=11863)
Local time is Sat Sep 12 14:17:54 UTC 2026
wproc: Successfully registered manager as @wproc with query handler
wproc: Registry request: name=Core Worker 11864;pid=11864
wproc: Registry request: name=Core Worker 11865;pid=11865
wproc: Registry request: name=Core Worker 11866;pid=11866
Successfully launched command file worker with pid 11877
^C
Nagios is a registered trademark of Nagios Enterprises, LLC. This guide is not affiliated with or endorsed by Nagios Enterprises.