Website Vidya
Linux & ServersStep-by-Step Guide

How to Install Nagios on Ubuntu 24.04

Complete guide to install Nagios on Ubuntu 24.04 LTS from source with Nagios Core, official plugins, Apache web console, and basic auth security.

RR
Rajesh RayLead Systems Educator
Published:
6 min read
PDF Cheat Sheet
How to Install Nagios on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

6 min read

Complete guide to install Nagios on Ubuntu 24.04 LTS from source with Nagios Core, official plugins, Apache web console, and basic auth security.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Installing Compilation Toolchains and Prerequisites
  • Step 2: Creating Dedicated User and Group Accounts
Grounded in full engineering runbookWebsiteVidya AI Engine

Proactive infrastructure observability is essential for maintaining high availability across enterprise servers, private clouds, and production networks. When you install nagios on ubuntu 24.04, you deploy a robust monitoring daemon that periodically checks system metrics—including CPU load, memory utilization, disk space, and daemon states—and alerts administrators before outages impact end users.

While older Linux distributions packaged outdated Nagios binaries in generic repositories, compiling Nagios Core directly from official source tarballs on Ubuntu 24.04 ensures that you run the latest release with updated security patches, modern glibc compatibility, and optimized GCC compiler flags. Combining the core engine with the official Nagios Plugins suite provides immediate monitoring coverage for HTTP, SSH, SMTP, ping, and database ports.

In this step-by-step guide, you will learn how to prepare Ubuntu 24.04 with necessary build toolchains, create dedicated service users and groups, compile and install Nagios Core, configure Apache virtual hosts with basic authentication, build the official Nagios Plugins, and access the web management dashboard.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A server running Ubuntu 24.04 LTS with at least 1 GB RAM and 10 GB storage.
  • A non-root user account with active sudo administrative privileges.
  • A command-line terminal with stable Internet connectivity.
  • Basic familiarity with executing compilation commands (make, gcc).

Step 1: Installing Compilation Toolchains and Prerequisites

Compiling Nagios Core and its graphical CGI web modules requires build utilities (build-essential), Apache web server, PHP, graphics libraries (libgd-dev), and cryptographic development headers.

Refresh your APT package database and install the complete development prerequisites.

Advertisement
# Refresh package repository index
sudo apt update && sudo apt upgrade -y

# Install build tools, Apache, PHP, and graphics libraries
sudo apt install -y autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php \
  libgd-dev libssl-dev libmcrypt-dev bc gawk dc build-essential

Step 2: Creating Dedicated User and Group Accounts

To enforce the principle of least privilege, Nagios should never run as the root superuser. Create a dedicated system user and group named nagios.

Additionally, create an external command group named nagcmd and add both the nagios service user and the Apache web server user (www-data) to this group. This allows the Apache CGI scripts to submit command requests to the Nagios core daemon.

# Create dedicated nagios user and group
sudo useradd nagios
sudo groupadd nagcmd

# Add nagios and www-data to the nagcmd group
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd www-data

Step 3: Downloading and Extracting Nagios Core Source Code

Download the latest stable Nagios Core source release tarball directly from the official GitHub releases portal into your temporary directory.

Extract the archive and navigate into the source directory.

Advertisement
# Navigate to /tmp directory
cd /tmp

# Download Nagios Core source tarball
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.5.2.tar.gz

# Extract the archive
tar -zxvf nagios-4.5.2.tar.gz

# Enter extracted directory
cd nagios-4.5.2

Step 4: Compiling and Installing Nagios Core

Initialize the source configuration script by specifying the command group (nagcmd). Once configuration finishes, build the binaries using make all.

Next, install the main program, systemd service units, sample configuration files, and external command directory permissions using the specialized make targets.

# Configure build with command group
./configure --with-command-group=nagcmd

# Compile Nagios binaries and documentation
make all

# Install core binaries and CGIs
sudo make install

# Install systemd unit script
sudo make install-init

# Install sample configuration files in /usr/local/nagios/etc/
sudo make install-config

# Configure external command file permissions
sudo make install-commandmode

Step 5: Configuring the Apache Web Console and Authentication

Install the Apache configuration file for the Nagios web console using make install-webconf. Enable the Apache rewrite and cgi modules required by the Nagios CGI dashboard.

Next, create an administrative web user named nagiosadmin and define a secure password using htpasswd. The default Nagios sample configuration expects this username for full administrative access.

# Install Apache configuration snippet
sudo make install-webconf

# Enable Apache CGI and rewrite modules
sudo a2enmod rewrite cgi

# Create web console administrator account
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

# Restart Apache to apply new virtual host and modules
sudo systemctl restart apache2

Step 6: Compiling and Installing Official Nagios Plugins

Nagios Core functions solely as a scheduling and alerting daemon; the actual host and service health checks are performed by standalone executable plugins located in /usr/local/nagios/libexec/.

Download, compile, and install the official Nagios Plugins collection.

# Navigate back to /tmp
cd /tmp

# Download Nagios Plugins source archive
wget https://nagios-plugins.org/download/nagios-plugins-2.4.8.tar.gz
tar -zxvf nagios-plugins-2.4.8.tar.gz
cd nagios-plugins-2.4.8

# Configure and compile plugins
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install

Step 7: Validating Configuration and Starting Nagios Service

Before starting the daemon, always run the Nagios verification utility (-v) against the master configuration file /usr/local/nagios/etc/nagios.cfg. This ensures there are no syntax errors or missing directives.

Once verification reports zero warnings and zero errors, enable and start the Nagios systemd daemon.

# Validate Nagios configuration syntax
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

# Enable and start Nagios service
sudo systemctl enable --now nagios

# Verify service is actively running
sudo systemctl status nagios

Step 8: Accessing and Navigating the Nagios Dashboard

Open your web browser and navigate to http://your_server_ip/nagios. Your browser will prompt you for HTTP basic authentication credentials.

Enter nagiosadmin and the password configured in Step 5. Once authenticated, the Nagios Core web console displays your monitoring overview, host states, service alerts, and performance graphs.

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

Nagios web interface shows: 'It appears as though you do not have permission to view information'

Resolution: This occurs if you created an Apache user with a name other than nagiosadmin. Edit /usr/local/nagios/etc/cgi.cfg and ensure your username is added to the authorized user parameters, or recreate the user as nagiosadmin using htpasswd.

Apache returns 404 Not Found when browsing /nagios

Resolution: Verify that the Nagios Apache configuration was loaded into /etc/apache2/sites-available/ or /etc/apache2/conf-available/nagios.conf. Enable the configuration with sudo a2enconf nagios and reload Apache with sudo systemctl reload apache2.

Plugins missing or returning 'check_ping: command not found'

Resolution: Ensure you compiled the plugins package with --with-nagios-user=nagios and ran sudo make install. Verify that executable binary files exist under /usr/local/nagios/libexec/.

Security Best Practices and Hardening

Always enforce strong passphrases on /usr/local/nagios/etc/htpasswd.users to prevent unauthorized visibility into your server infrastructure.

Deploy an SSL/TLS certificate with Let's Encrypt Certbot (sudo certbot --apache) so monitoring credentials are not transmitted in plain text.

Restrict web console access in Apache (/etc/apache2/conf-available/nagios.conf) to trusted internal administrator IP ranges using Require ip directives.

Do not run the Nagios daemon or any monitoring plugins as the root user account.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

3 FAQs
Yes. By installing the Nagios Remote Plugin Executor (NRPE) on remote Linux hosts or NSClient++ on Windows machines, Nagios Core can query remote disk, memory, and service states securely.
Define new host and service objects inside /usr/local/nagios/etc/objects/ (e.g. hosts.cfg or services.cfg), reference them in nagios.cfg, verify syntax with nagios -v, and reload the service.
Primary daemon logs and event histories are written to /usr/local/nagios/var/nagios.log.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout