Enter your email address below and subscribe to our newsletter

How to Install Nmap on Linux [4 Ways]

Learn how to install Nmap on Linux by 4 simple and easy methods.

Share your love

Nmap (Network Mapper) is a powerful free and open-source utility for network discovery and security auditing. It is an essential tool in any network administrator’s or ethical hacker’s toolkit.

Nmap allows you to rapidly scan networks to determine what hosts and services are running, find open ports, identify operating systems and software versions, and detect vulnerabilities.

So in this tutorial, I will walk you through four ways you can install Nmap on Linux:

  • Using the package manager (easy)
  • Using the Snap package manager
  • Compiling from source code
  • Running in a Docker container

Let’s start with the first one.

1. Install Nmap using a package manager

By far, this is the easiest way you can install Nmap on Linux as Nmap is one of the most popular security auditing tools, it is available in the default repository of almost every Linux distribution.

From here, I will provide commands for multiple Linux distributions so you can scroll a bit till you find your Linux distribution and install Nmap.

For Ubuntu/Debian:

If you are using Ubuntu or any other Debian-based Linux distribution, then, you can execute the following command:

sudo apt update && sudo apt install nmap

For RHEL/CentOS:

If you are using enterprise Linux from RHEL, then you can use the given command to install Nmap using the yum package manager:

sudo yum install nmap

For Fedora:

If you are using Fedora or other derivatives of Fedora, then you can use the dnf package manager to install Nmap:

sudo dnf install nmap

For openSUSE:

Here comes my favourite one (as I’ve recently switched to openSUSE). openSUSE uses a zypper package manager and you can use the following command to use zypper to install Nmap:

sudo zypper install nmap

For Arch Linux:

If you use Arch btw, you can use the following command to install Nmap on your system:

sudo pacman -S nmap

If your distribution was not included in this list, then you can refer to the other methods that I’m about to show which are universal and will work on any Linux distribution irrespective of what Linux distribution you are using.

2. Install Nmap using the snaps

No matter how much you hate snaps, one thing that I can assure you is it makes the installation process smooth. Before you jump on to the installation part, make sure you have snaps configured on your system.

Ubuntu users don’t have to worry about this but if you are using anything else and if you haven’t configured snaps for your machine, then you can visit the official configuration page for snaps. Don’t worry, it’s just one command process and you’ll be good to go.

Once done, Nmap can be installed by a single command:

sudo snap install nmap

3. Install Nmap by compiling it from source

To install Nmap by compiling it from the source, you first need to install some prerequisites which will be used to compile the source code. You need two packages: build-essential and libssl-dev.

If you are an Ubuntu user, you can use the following command to install prerequisites:

sudo apt install build-essential libssl-dev automake

Now, enter the version number of Nmap that you want to install in the given command to download the tarball file for the Nmap:

wget https://nmap.org/dist/nmap-[version].tar.bz2

While writing this tutorial, the latest version of Nmap is 7.95 and I will be installing that for this tutorial:

wget https://nmap.org/dist/nmap-7.95.tar.bz2
Install Nmap in Linux by compiling it from source

Once you are done downloading the tarball file, extract the file content using the following command:

tar jxvf nmap-*.tar.bz2

Now, change your directory to where the files were extracted. It will be named as nmap-[version]:

cd nmap-[version]
Compile nmap from source on linux

Finally, use the following commands one by one to compile binaries and install them on your computer:

./configure
make
sudo make install

While compiling, if you get an error saying:

/usr/bin/python3 -m build zenmap/
/usr/bin/python3: No module named build
make: *** [Makefile:364: build-zenmap] Error 1

To solve this error, you can skip the compilation of zenmap so, your compilation steps would look like this:

./configure --without-zenmap
make
sudo make install

After installation, you can check the installed version by using the following command:

nmap --version
Install the latest version of Nmap on Linux

4. Install and use Nmap in Docker

If you prefer containerisation and want to do the same with Nmap, then there’s good news for you. Nmap is also available as a docker image and can be used in Docker.

For that, first, you need to install Docker and if you are using Ubuntu, then you can use the following command to install Docker:

sudo apt install docker.io docker-compose

Once you are done with the installation, pull the Docker image of Nmap using the given command:

sudo docker pull instrumentisto/nmap
Install Docker Nmap image

Now, you can execute the Nmap command via docker as shown here:

docker run -it --rm instrumentisto/<nmap with flags>

For example, if I want to execute the nmap command to check the version, then my command would look like this:

docker run -it --rm instrumentisto/nmap -v
Install nmap in docker

There you have it!

Wrapping Up…

In this tutorial, I went through four ways you can install Nmap on Linux including default package manager, snaps, compiling it from source (with error solution) and using it inside Docker. I find the first method most efficient.

Share your love
Kabir
Kabir

A tech journalist whose life revolves around networks.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!