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 --versionIf 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
| Step | Command | Purpose | Successful outcome |
|---|---|---|---|
| Check installed status | nmap --version | Determine whether the executable is already available | A version is displayed, or the terminal reports that the command is unavailable |
| Refresh package metadata | sudo apt update | Retrieve current package index information | APT updates its local package lists |
| Install the package | sudo apt install nmap | Download and install Nmap and required dependencies | APT completes without an error |
| Verify the version | nmap --version | Confirm that the installed executable launches | Nmap 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 updatesudo 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 nmapAPT 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 nmapFor 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 --versionA 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 nmapA 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 --helpThis 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.1Results 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 symptom | Likely meaning | Recommended response |
|---|---|---|
| Nmap version output appears | Nmap is installed and reachable through PATH | No installation is needed; use nmap --help to review basic usage |
| Nmap command is not found | Nmap is not installed, or its executable is not reachable through PATH | Run 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 package | Package metadata is outdated or configured Ubuntu repositories are unavailable, disabled, or misconfigured | Run sudo apt update and review repository errors. Check network access and configured software sources before retrying |
| Permission denied or sudo authentication failure | Your user lacks sudo privileges, or the password was incorrect | Use an account authorized to run administrative commands, or ask an administrator to install the package |
| Repository or network update failure | There may be no network connection, an unreachable mirror, or a proxy or firewall problem | Check 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
- Run
nmap --versionbefore installing; a valid version means Nmap is already available. - Refresh Ubuntu's package index with
sudo apt update. - Install Nmap with
sudo apt install nmap, accepting the prompt withYif appropriate. - Run
nmap --versionagain to confirm the installation. - Use
nmap --helpor scan only127.0.0.1for a safe initial test.
For the broader Linux installation topic, see Install Nmap on Linux.