How to Install Nagios 4 on Ubuntu Linux

How to Install Nagios 4 on Ubuntu Linux

I found myself needing to install Nagios on Ubuntu Linux. Sadly, most of the guides I was attempting to follow online were somewhat dated and/or lacking. So why not create the walk-through here myself to potentially help others as well?

For the purpose of this guide, I’m assuming you have a blank/clean Ubuntu Linux box. I personally recommend using DigitalOcean for $5/month.

Start by updating the Droplet, and installing the necessary dependencies:

sudo apt-get update
sudo apt-get install wget build-essential unzip openssl libssl-dev
sudo apt-get install apache2 php libapache2-mod-php php-gd libgd-dev


Next, create the Nagios user. After this command, it will ask for you to create a password.

sudo adduser nagios


Next, we’ll create the Nagios “nagcmd” group, and add our user to it that we created in the previous step. We also want to add the nagios user to the Apache group so we can run and access the front-end Nagios app (when we get to that point).

sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd www-data


As of this writing, Nagios 4.4.3 is the newest version of Nagios Core. Update these values to reflect newer versions.

cd /opt/
tar xzf nagios-4.4.3.tar.gz


Now we change to the Nagios directory, make, compile, and install.

cd nagios-4.4.3
sudo ./configure --with-command-group=nagcmd
sudo make all
sudo make install
sudo make install-init
sudo make install-daemoninit
sudo make install-config
sudo make install-commandmode
sudo make install-exfoliation


Setup event triggers for the web interface.

cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers


Now we’ll create the Apache configuration for the Nagios interface.

sudo vi /etc/apache2/conf-available/nagios.conf


Then paste in the following:

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Restricted Area"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Restricted Area"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user


We then want to create the admin user and set the password for the web interface. Unless you specifically need a different username, stick with nagiosadmin.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin


Enable a few different Apache configurations, and then restart Apache.

sudo a2enconf nagios
sudo a2enmod cgi rewrite
sudo service apache2 restart


Install some required Nagios plugins.

cd /opt/
tar xzf nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1


Make, compile, and install said Nagios plugins.

sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
sudo make
sudo make install


Once complete, run this command. This is a quick Nagios self-check. It will run through the various files and system checks to ensure that everything is running as it should.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg


If everything looks good and without error, start Nagios and set it to run automatically after a reboot.

service nagios start
sudo systemctl enable nagios


Once completed, be sure to do some cleanup and remove the tarballs that we downloaded earlier.

rm /opt/nagios-4.4.3.tar.gz
rm /opt/nagios-plugins-2.2.1.tar.gz


You can then access the Nagios web interface by entering your domain name or IP address, followed by “/nagios/”



After authentication with nagiosadmin and the password we set previously, you should be greeted with this page:

how to install nagios on ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *