VMware ESXi and vSphere Cluster Management

How to Install Nmap on Ubuntu Linux

Learn how to check for Nmap, refresh Ubuntu package metadata, install Nmap with APT, verify it, and run a safe local test.

What Nmap is

Nmap is a command-line utility for network discovery and security auditing. It can identify hosts, services, and other details on a network.

Only scan systems and networks that you own or are explicitly authorized to assess. Even a simple scan can be considered unauthorized activity on someone else's equipment.

Ubuntu, APT, and Linux package managers

Ubuntu is a Linux distribution with Debian-derived package management. Ubuntu commonly uses APT to retrieve and install software from configured repositories. A repository is a software source that provides package metadata and packages.

Installation commands differ among Linux distributions. The commands in this lesson are for Ubuntu and should not be assumed to work unchanged on Fedora, Arch Linux, openSUSE, or other distributions.

apt is the user-oriented APT command commonly used interactively. apt-get is a long-established APT command that is often used in scripts or shown in older documentation. Both can install the Ubuntu Nmap package.

Check whether Nmap is already installed

Open a terminal and run:

nmap --version

If Nmap is installed and available through your shell's PATH, the command displays its version and build information. PATH is the environment setting that tells the shell which directories to search for executable commands.

If Nmap is not available, the shell reports that nmap was not found or a package helper suggests a package to install. If a valid Nmap version is displayed, no installation is needed.

Ubuntu installation workflow

StepCommandPurposeSuccessful outcome
Check installed statusnmap --versionDetermine whether the executable is already availableA version is displayed, or the terminal reports that the command is unavailable
Refresh package metadatasudo apt updateRetrieve current package index informationAPT updates its local package lists
Install the packagesudo apt install nmapDownload and install Nmap and required dependenciesAPT completes without an error
Verify the versionnmap --versionConfirm that the installed executable launchesNmap displays its version and build information

Refresh Ubuntu package metadata

APT uses a local package index: metadata describing packages and versions available from configured repositories. Refresh this information before installing so APT can use current package information.

Run:

sudo apt update

sudo runs an authorized command with elevated administrative privileges. Ubuntu may ask for your user password. Password characters normally do not appear while you type; enter the password and press Enter.

This command updates package metadata. It does not upgrade the software already installed on your system. Upgrading installed packages is a separate operation.

Install Nmap with APT

After the metadata update completes successfully, install Nmap with:

sudo apt install nmap

APT may show the Nmap package, additional dependencies, download size, and disk-space usage. A dependency is an additional package required for software to function.

When APT displays a confirmation prompt such as Do you want to continue? [Y/n], type Y and press Enter to accept. Type n and press Enter to decline or cancel the installation.

You may also encounter the equivalent command using the older, long-established APT interface:

sudo apt-get install nmap

For an interactive Ubuntu terminal, sudo apt install nmap is the usual form. Do not run both commands unnecessarily; either successful command installs the package.

Verify the completed installation

Run the version command again:

nmap --version

A displayed version confirms that the Nmap executable is installed and available on the command path. You can also inspect the Debian package state with:

dpkg -l nmap

A successful package listing shows the Nmap package as installed. The version command is still a useful practical check because it confirms that the command launches from your current shell.

Safe next steps

To confirm that Nmap starts without scanning another system, display its help:

nmap --help

This prints usage information and does not scan a target.

If you want a minimal local-only test, scan localhost, which means the local computer and is commonly represented by 127.0.0.1:

nmap 127.0.0.1

Results depend on services listening on your computer. A result showing no open ports can be valid and does not indicate that installation failed.

Common installation outcomes

Terminal message or symptomLikely meaningRecommended response
Nmap version output appearsNmap is installed and reachable through PATHNo installation is needed; use nmap --help to review basic usage
Nmap command is not foundNmap is not installed, or its executable is not reachable through PATHRun sudo apt update, then sudo apt install nmap. If the package is confirmed installed but the command remains unavailable, open a new terminal and inspect PATH
APT cannot locate the nmap packagePackage metadata is outdated or configured Ubuntu repositories are unavailable, disabled, or misconfiguredRun sudo apt update and review repository errors. Check network access and configured software sources before retrying
Permission denied or sudo authentication failureYour user lacks sudo privileges, or the password was incorrectUse an account authorized to run administrative commands, or ask an administrator to install the package
Repository or network update failureThere may be no network connection, an unreachable mirror, or a proxy or firewall problemCheck connectivity and retry sudo apt update. Review repository and proxy settings, or use an approved reachable mirror

Troubleshooting details

The command is unavailable after installation

First verify that the installation completed without errors. Run dpkg -l nmap and then nmap --version. If the package is installed but the shell still cannot find the command, open a new terminal and investigate the current PATH.

APT cannot find Nmap

Run sudo apt update and read its output for repository errors. Verify that the computer has network access and that Ubuntu software sources are enabled and correctly configured. Retry the installation only after the package index updates successfully.

Sudo or permission errors

If sudo rejects the password, enter the password for the current authorized user carefully. If the user is not permitted to use sudo, an administrator must install Nmap or provide appropriate access.

APT cannot download packages

Check the network connection and retry the package index update. A repository mirror may be temporarily unreachable, or a proxy or firewall may block package access. Persistent failures require reviewing the configured repository and proxy settings.

The localhost scan reports no open ports

This usually means that no services are listening on the scanned ports, or that local firewall rules affect visibility. Treat it as a scan result, not an installation failure. Use nmap --version or nmap --help to verify installation.

Summary

  1. Run nmap --version before installing; a valid version means Nmap is already available.
  2. Refresh Ubuntu's package index with sudo apt update.
  3. Install Nmap with sudo apt install nmap, accepting the prompt with Y if appropriate.
  4. Run nmap --version again to confirm the installation.
  5. Use nmap --help or scan only 127.0.0.1 for a safe initial test.

For the broader Linux installation topic, see Install Nmap on Linux.