Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 36 ยท Getting Started

Installing Nmap

Install Nmap on Linux, macOS and Windows, verify the version, understand Npcap and root privileges, and set up a safe home lab target to practice on.

Nmap runs on Linux, macOS, Windows and several other systems. Installing it takes a minute, but two details trip up beginners: raw packets need elevated privileges, and on Windows you also need a packet-capture driver called Npcap. This lesson walks through each platform, shows how to check that the install works, and sets up a safe target to practice on.

Nmap commands on this page are read-only. Run them on your own computer, in a terminal, against machines you own. The Python editors are stand-ins that run in your browser.

Install on Linux

Most distributions ship Nmap in their package repositories. The package is simply called nmap.

Terminal
# Debian, Ubuntu, Kali, Linux Mint
sudo apt update
sudo apt install nmap

# Fedora, RHEL, Rocky, AlmaLinux
sudo dnf install nmap

# Arch Linux
sudo pacman -S nmap

# openSUSE
sudo zypper install nmap

Distribution packages are sometimes a little behind the newest release. If you want the latest version you can download the source or an RPM from the official site, https://nmap.org/download, and verify its signature or checksum as the page describes. Never download Nmap from a site you do not trust: a trojaned scanner is a classic trap.

Install on macOS

The easiest way is Homebrew:

Terminal
brew install nmap

You can also use the official installer from nmap.org. After either method the nmap command is available in Terminal.

Install on Windows

Download the self-installer (nmap-<version>-setup.exe) from nmap.org. It bundles three things:

  1. nmap.exe, the scanner;
  2. Npcap, the packet capture and injection library Nmap needs on Windows (the successor to WinPcap);
  3. Zenmap, the graphical front end (in older installers; newer releases may not include it, and the command line is the focus of this course).

Accept the Npcap prompt during setup. If a scan later fails with "Failed to open device" or "dnet" errors, reinstall Npcap with the "WinPcap API-compatible mode" option and run the terminal as Administrator. Windows also offers a package route: winget install Insecure.Nmap or choco install nmap, if you use those tools.

Verify the installation

Open a terminal and ask Nmap for its version:

Terminal
nmap --version

Example output (shape only; your version numbers will differ):

TEXT
Nmap version 7.9x ( https://nmap.org )
Platform: x86_64-pc-linux-gnu
Compiled with: liblua-5.4.x openssl-3.x.x libssh2-1.x nmap-libpcre2-10.x libz-1.x.x libpcap-1.x.x nmap-libdnet-1.12 ipv6
Compiled without:
Available nsock engines: epoll poll select

Three lines matter early on: the version (old versions lack newer scripts), liblua (needed for the scripting engine), and ipv6 (so you can scan IPv6 addresses). If nmap is "not found", the install directory is not on your PATH; on Windows open a new terminal after installing.

You can also ask for help text:

Terminal
nmap -h      # short option summary
man nmap     # the full manual page on Linux and macOS

Privileges: why sudo matters

Many scan types craft their own packets with raw sockets, and operating systems reserve raw sockets for administrators. So Nmap behaves differently depending on who runs it:

Run as Default TCP scan Host discovery on a local network
Normal user TCP connect scan (-sT) uses the OS network stack TCP probes only
root / Administrator SYN scan (-sS) with raw packets ARP requests on a local Ethernet

So nmap target and sudo nmap target can produce slightly different results and speed. Using sudo is normal for scanning, but remember that you are giving the program full privileges: install Nmap only from trusted sources, and do not run random third-party scripts as root.

A safe place to practice

You need a target you are allowed to scan. Good options:

  • Your own machine: nmap 127.0.0.1 or nmap localhost scans your computer through its loopback interface and never leaves it.
  • A virtual machine on a host-only network (VirtualBox, VMware, Hyper-V, or Docker containers) that you run yourself.
  • Your home network, if the router and devices are yours.
  • scanme.nmap.org, a server the Nmap project provides for people to test. Their terms ask for polite, light use (no heavy or repeated scans), and they can change. Check the page http://scanme.nmap.org before you use it.

Do not scan your school, workplace, a neighbor, or random public addresses, even "just to look". See Legal and Ethical Scanning.

A stand-in: checking a version string

Scripts often need to check that Nmap is new enough. The comparison trap is that 7.100 is newer than 7.95, so you cannot compare version strings as text. This stand-in parses output like the nmap --version line and compares numbers properly.

Python Compare Nmap versions correctly

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A stand-in: do I need root for this scan?

The table above can be turned into a small decision helper. Given a scan type and your privilege level, the function says what Nmap will do. The rules are simplified from the real behavior.

Python Which scan will Nmap choose?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

(-sV, version detection, builds on a port scan, so by itself it does not need raw packets.)

Troubleshooting quick list

  • "nmap: command not found": the install folder is not on PATH; reopen the terminal, or reinstall.
  • "You requested a scan type which requires root privileges": add sudo (Linux/macOS) or use an Administrator terminal (Windows).
  • "Failed to open device" on Windows: Npcap is missing or broken; reinstall it.
  • All ports show filtered: a firewall (maybe on your own machine) is dropping probes.
  • Everything is very slow: a VPN, Wi-Fi or filtering firewall; see timing options in Chapter 7.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which package name installs Nmap on Debian-based Linux?

    The package is simply called nmap: sudo apt install nmap.
  2. 2. What extra component does Nmap need on Windows to send raw packets?

    Npcap is the packet capture and injection library bundled with the Windows installer.
  3. 3. You run a plain nmap target as a normal (non-root) user. Which TCP scan type is used by default?

    Without raw-socket privileges Nmap falls back to the connect scan, which uses the operating system's normal connect call.
  4. 4. Which address is a safe target that never leaves your own computer?

    127.0.0.1 is the loopback address of your own machine.

Summary

  • Install Nmap from your package manager, Homebrew, or the official Windows installer, and download only from nmap.org.
  • Windows needs Npcap; elevated privileges unlock raw-packet scans.
  • nmap --version confirms the install and shows the version, Lua and IPv6 support.
  • Practice on loopback, your own VMs, your own network, or scanme.nmap.org used lightly.
  • Compare versions as numbers, not as text.

Next: Legal and Ethical Scanning