Installing Network Simulator 2 (NS2) on Ubuntu 14.04

1 Introduction

Network simulators are tools used to simulate discrete events in a network and which helps to predict the behaviours of a computer network. Generally the simulated networks have entities like links, switches, hubs, applications, etc. Once the simulation model is complete, it is executed to analyse the performance. Administrators can then customize the simulator to suit their needs. Network simulators typically come with support for the most popular protocols and networks in use today, such as WLAN,UDP,TCP,IP, WAN, etc.

Most simulators that are available today are based on a GUI application like the NCTUNS while some others incl. NS2 are CLI based. Simulating the network involves configuring the state elements like links, switches, hubs, terminals, etc. and also the events like packet drop rate, delivery status and so on. The most important output of the simulations are the trace files. Trace files log every packet, every event that occurred in the simulation and are used for analysis. Network simulators can also provide other tools to facilitate visual analysis of trends and potential trouble spots. Most of the simulation is performed in discrete time intervals where events that are in the queue are processed one after the other in an order.

Since simulation is a complex task, we cannot guarantee that all the simulators can provide exact or accurate results for all the different type of information. Examples of network simulators are: ns, NCTUNS, NetSim, etc.

ns2 is a name for series of discrete event network simulators like ns-1, ns-2 and ns-3. All of them are discrete-event network simulators, primarily used in research and teaching. ns2 is free software, publicly available under the GNU GPLv2 license for research, development, and use.

This post deals with the installation of "ns2" also called the "network simulator 2" in Ubuntu 14.04.

2 Download and Extract ns2

Download the all in one package for ns2 from here

The package downloaded will be named "ns-allinone-2.35.tar.gz". Copy it to the home folder. Then in a terminal use the following two commands to extract the contents of the package.:

cd ~/
tar -xvzf ns-allinone-2.35.tar.gz

All the files will be extracted into a folder called "ns-allinone-2.35".

3 Building the dependencies

Ns2 requires a few packages to be pre installed. It also requires the GCC- version 4.3 to work correctly. So install all of them by using the following command:

sudo apt-get install build-essential autoconf automake libxmu-dev

One of the dependencies mentioned is the compiler GCC-4.3, which is no longer available, and thus we have to install GCC-4.4 version. The version 4.4 is the oldest we can get. To do that, use the follwoing command:

sudo apt-get install gcc-4.4

The image below shows the output of executing both the above commands. If you have all the dependencies pre-installed, as I did, the output will look like the image below:

Once the installation is over , we have to make a change in the "ls.h" file. Use the following steps to make the changes:

Navigate to the folder "linkstate", use the following command. Here it is assumed that the ns folder extracted is in the home folder of your system.

cd ~/ns-allinone-2.35/ns-2.35/linkstate

Now open the file named "ls.h" and scroll to the 137th line. In that change the word "error" to "this->error". The image below shows the line 137 (highlighted in the image below) after making the changes to the ls.h file.To open the file use the following command:

gedit ls.h

Save that file and close it.

Now there is one more step that has to be done. We have to tell the ns which version of GCC will be used. To do so, go to your ns folder and type the following command:

Sudo gedit ns-allinone-2.34/otcl-1.13/

In the file, change Change CC= @[email protected] to CC=gcc-4.4, as shown in the image below.

4 Installation

Now we are ready to install ns2. To do so we first require root privileges and then we can run the install script. Use the following two commands:

sudo su cd ~/ns-allinone-2.35/./install

The following is a snap of these commands:

The image below shows how it looks upon successful execution

It took almost 6 minutes to build and install ns2 on my system. But before we run it, we need to add the build path to the environment path.

5 Setting the Environment Path

The final step is to tell the system, where the files for ns2 are installed or present. To do that, we have to set the environment path using the ".bashrc" file. In that file, we need to add a few lines at the bottom. The things to be added are given below. But for the path indicated below, many of those lines have "/home/akshay/ns-allinone-2.35/...." , but that is where I have my extracted folder. Make sure you replace them with your path. For example, if you have installed it in a folder "/home/abc", then replace "/home/akshay/ns-allinone-2.35/otcl-1.14" with "/home/abc/ns-allinone-2.35/otcl-1.14".

Do this for all the required lines.

sudo gedit ~/.bashrc

Lines to be added:

#the above two lines beginning from xgraph and ending with unix should come on the same line

Once the changes have been made, save the file and restart the system.

6 Running ns2

Once the system has restarted, open a terminal and start ns2 by using the following command:


If the installation is correct then the terminal looks like the image below :

Share this page:

Suggested articles

54 Comment(s)

Add comment


From: Jaspreet Kaur

I m currently working on SAODV in manet. Can you please mail me the source code of SAODV in ns2. In which hash chain and digital signature is being embedded into AODV. 

From: aaram

thank you so much. that was really helpful.

From: Mauricio

Excelent instructions. It works for me on Xubuntu.

From: mukesh verma

thanks a lot......

From: Pardeep Peddy

Perfect guide.... installed straight away.


From: Dave Mc

Works perfectly on Ubuntu 15.04,,Excellent instructions!

From: punitha

  I could not save the file after making changes in the ls.h file. It is displaying a message as Could not save the file “/home/user/ns-allinone-2.35/ns-2.35/linkstate/ls.h”.You do not have the permissions necessary to save the file. Please check that you typed the location correctly and try again. Can someone help me ?

From: Ravi Kumar

Perfect guided of ns2 installation.

From: Akshay

My ./install is not working as given above. The image you provided doesnt match with mine.

Output for mine is 




.Makefile:1601: warning: overriding commands for target `/home/akshay/Desktop/Networking'

Makefile:1514: warning: ignoring old commands for target `/home/akshay/Desktop/Networking'

Makefile:1603: warning: overriding commands for target `/home/akshay/Desktop/Networking'

Makefile:1601: warning: ignoring old commands for target `/home/akshay/Desktop/Networking'

Makefile:1605: warning: overriding commands for target `/home/akshay/Desktop/Networking'

Makefile:1603: warning: ignoring old commands for target `/home/akshay/Desktop/Networking'

make: Circular /home/akshay/Desktop/Networking

make: Circular softs/ns-allinone-2.35/tcl8.5.10/unix/../macosx/configure

make: *** No rule to make target `softs/ns-allinone-2.35/tcl8.5.10/unix/../macosx/', needed by `softs/ns-allinone-2.35/tcl8.5.10/unix/../macosx/configure'.  Stop.

tcl8.5.10 make failed! Exiting ...

For problems with Tcl/Tk see


From: pratibha

easy instructions.......thanks a lot.....

From: Pavan

Hey, I could install ns2 properly according to your steps! They even matched with snapshots associated with every command of yours. But when I restarted my system and tried giving 'ns' command, it says

"The program 'ns' is currently not installed. You can install it by typing:sudo apt-get install ns2"

I'll be very thankful if I get a response to my problem. :)

From: lichuhuang

Thank you!

From: Prasad

how to run NS2 on ubuntu

From: Ashish Malani

Thanks a lot !!

Very well explained

From: chandrabhan pradhan

Did not work in Ubuntu 15.04


From: ayoub sarvetani

thank you.

From: elmira

im working in vanet topic. in step 3 i have error and idont know how to fix it.please help me.

error schema: Reading package lists... Done

Building dependency tree       

Reading state information... Done

Package autoconf is not available, but is referred to by another package.

This may mean that the package is missing, has been obsoleted, or

is only available from another source


E: Unable to locate package build-essential

E: Package 'autoconf' has no installation candidate

E: Unable to locate package automake

E: Unable to locate package libxmu-dev

From: lucas

thx a lot. It was of great help!

From: shehu

I followed your procedure but when I typed nam I got the following error: Segmentation fault(core dumped).

Kindly advice further.


From: akhil pulimath

thankyou verymuch and very helpful




I've done all that has been saidUnfortunately, when I enter commands and files to be builtInside that no contentHelp me please


I enter the following commands I

#create a new simulator objectset ns [new Simulator]#open the nam trace fileset nf [open out.nam w]$ns namtrace-all $nf#define a 'finish' procedureproc finish {} {global ns nf$ns flush-trace#close the trace fileclose $nf#execute nam on the trace fileexec nam out.nam &exit 0}

#create two nodesset n0 [$ns node]set n1 [$ns node]#create a duplex link between the nodes$ns duplex-link $n0 $n1 1Mb 10ms DropTail

From: priya

my nam windowis not opening but did installation properly

From: vikash kumar

sir i have succesfully installed ns2 now how to open it please suggest me..

From: aimi19930326

hello ,when i do "na reconnect.tcl",it has a problem like this "

    (_o10 cmd line 1)

    invoked from within

"_o10 cmd get-bgp-agent"

    invoked from within

"catch "$self cmd $args" ret"

    invoked from within

"if [catch "$self cmd $args" ret] {

set cls [$self info class]

global errorInfo

set savedInfo $errorInfo

error "error when calling class $cls: $args" $..."

    (procedure "_o10" line 2)

    (SplitObject unknown line 2)

    invoked from within

"$n0 get-bgp-agent"

    invoked from within

"set bgp_agent0 [$n0 get-bgp-agent]"

    (file "reconnect.tcl" line 27)

"could you help me solve this problem ,thank you in advance ?

From: vi

thanks lots


while installing mannasim in ns2.35 this error found


configure: error: Installation of tcl seems incomplete or can't be found automatically.Please correct the problem by telling configure where tcl isusing the argument --with-tcl=/path/to/package(perhaps after installing it),or the package is not required, disable it with --with-tcl=no.

From: Srikar

I have the same error as well while using ./configure

If you've found a solution, please let me know:email: [email protected] be of tremendous help!

From: Mariem


I have the same problem when I run ./configure can you help me if you've found a solution and thanks a solution,


From: Mariem Ben Rekhissa

Hello Sir,

I have the same problem when I run ./configure so can you help me please if you have found the solution and thanks in advance

From: karuppaiah

how to install ns2 in boss linux GNOME version 3.4.2

From: david

hi i received this message

make: gcc-4.4: Command not foundMakefile:91: recipe for target 'libotcl.a' failedmake: *** [libotcl.a] Error 127otcl-1.14 make failed! Exiting ...See  

what do i? result of gcc --version is 5.2.1 or 5.2.1 20151010

From: Jyoti

[email protected]:~$ sudo su cd ~/ns-allinone-2.35/./installNo passwd entry for user 'cd'

From: Anup Patil

Can anyone tell me how to configure NAM after configuring above setting for visualization??

From: Vinayak opened as empty....! plz help me

From: Vaishali

@Vinayak May be you are also doing the same mistake which I was doing.

Check the path again its cd ns-allinone-2.35/otcl-1.14  and then type the command gedit

From: piyush09

Hello , I am facing this error, kindly resolve it 

config.status: creating Makefile

rm -f libotcl.a otcl.o

gcc-4.4 -c -g -O2 -DNDEBUG -DUSE_SHM -DHAVE_UNISTD_H=1 -I. -I/home/piyush/ns-allinone-2.35/include -I/home/piyush/ns-allinone-2.35/include -I/home/piyush/ns-allinone-2.35/include -I/include  otcl.c

make: gcc-4.4: Command not found

make: *** [libotcl.a] Error 127

otcl-1.14 make failed! Exiting ...

See for problems


From: Sakshi Dubey

Awesome tutorial...very clear steps

From: Behzad

Perfect guide!.thank U alot

From: Gerald Nathan Balekaki

Well Documentated installation manual. i just done it perfectly simple because of your candid guide. Cheers

From: Adnan

Hi,Please guide me if i want to install some earlier version of NS 2.That is NS2-1b4.then there will be same process and pre-requisite or any different way please guide me...or from where i can get the details please

From: Afsah

Many thanks for guide. I have installed ns-2.31 on Ubuntu 16.04. When i write ns in the terminal, the % sign appears, but while writing nam on the terminal, following error occurs "segmentation fault (core dumped). Please suggest me the solution to rectify this. Thanks in advance

From: Anjaiah Induri

Hey Akshay! I've installed according to your steps. Everything was successful. After restarting the system I tried to run command ns in terminal, it shows the following response.

"The program 'ns' is currently not installed. You can install it by typing:sudo apt-get install ns2"

I'll be very thankful if I get a response to my problem. :)

From: thamizh

thank u so much bro

From: Sneha

Do NSG support heterogeneous transmission range?


From: Shwetha

I followed your procedure but when I typed nam I got the following error: Segmentation fault(core dumped).

Kindly advice further.


From: Shwetha

Hello plz help me, i have installed properly but now getting error like segmentation fault(Core dumped), plz give me the solution for this..

Thanks in Advance.

From: Yanutomo

haii i'm new about ns2

currently i work in umts network, does this included with umts patch?

because i've search the umts patch and i can't find it, please someone help me

From: Leo

Thank you for the guidance. I was very helpful.

From: ankita

sir my nam file is not opening .when i write nam in in terminal then it shows segmentation fault .in desktop for example demo.nam is genrating.what should i do?


From: misbah

sir, i am a PG student, i am getting problem while installing xgraph nsnam and gnuplot. it's showing some segmentation error. kindly help me please.

From: pratiksha

i get segmentation eorror when i run nam file 

can you please help me in that

From: Armin

Im installing ns-2.35 on ubuntu 16.04, i got the following error:


* Build OTcl-1.14


./install: 489: ./install: ./configure: Permission denied

otcl-1.14 configuration failed! Exiting ...

Please check

for common problems and bug fixes.

[email protected] // :/home/armin/ns-allinone-2.35# 

From: zannou

if ns not work ,you must restart computer the enter sudo su then ns

From: vijay sethupathi

ns2 is not installing due to the impropre network services