Installing Network Simulator 2 in Ubuntu
by karthikselvakumar
Are you baffled by random errands saying “ ns2 doesn’t work on ubuntu ” and so ?
Are you a linux geek don’t wanna boot to windows for network simulator software ?
did your lab admin made a mess with your system in the name of installing ns2
?
then you are in a right place ![]()
You can make NS working in your system by putting little effort on your ubuntu
Step 1:
Download network simulator software from here
if you prefer other old versions you can swich by viewing files in that page
the file will be of almost 57 MB
Step 2:
Extract the files to your own desired directory
I did in /home/karthik/Desktop/
step 3:
now go to your working directory of ns2 by
cd /home/karthik/Desktop/ns-allinone-2.34
step 4:
Run this command to check any unresolved dependencies existing between installation
sudo apt-get install build-essential autoconf automake libxmu-dev
run the command ./install in terminal
it will take around 5 minutes
step 5:
Well Thats were your installation of ns2 exits
now you have to configure to make it alive
you have to edit in the shell
run gedit ~./bashrc
add at end of the file this lines
remember change /home/karthik/Desktop/ to your file path say /home/host-name/
# LD_LIBRARY_PATH
OTCL_LIB=/home/karthik/Desktop/ns-allinone-2.34/otcl-1.13
NS2_LIB=/home/karthik/Desktop/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_
LIB:$USR_LOCAL_LIB
# TCL_LIBRARY
TCL_LIB=/home/karthik/Desktop/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/home/karthik/Desktop/ns-allinone-2.34/bin: /home/karthik/Desktop/
ns-allinone-2.34/tcl8.4.18/unix : /home/karthik/Desktop/ns-allinone-2.34/tk8.4.18/unix
NS=/home/karthik/Desktop/ns-allinone-2.34/ns-2.34/
NAM=/home/karthik/Desktop/ns-allinone-2.34/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM
now save the file and close it
run source ~/.bashrc
ignore if any errors
then run ./validate
this is the longest step it takes 30-45 minutes hence you can have a meal during the course of time
step 6:
this is editing thing ( optional )
just make links to the files in /home/karthik/Desktop/ns-allinone-2.34/bin by right click on all files and choose make link
copy all and paste to /usr/bin/ directory by running
sudo nautilus
then rename the file name for eg) link to ns to ns and so on . do this till all files are renamed .
step 7:
Sample code
now u can check out a demo to test you ns 2 by writing a sample code as below :
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a ‘finish’ procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}
#Create two nodes
set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 “finish”
#Run the simulation
$ns run
now copy this code and paste to a file say myfirstprogram.tcl
then run ns myfirstprogram.tcl
you must see a window like this :
and … You did it , Enjoy

problem!! :X
followed all the steps till 5
i didnt understand how to use nautilus. so, some how managed to paste the links in to the /usr/bin directory.
i didnot find a file named ns among them….
anyways tried to run ns from terminal. but, as expected, command not found was the result….
any help is appreciated.
ty
can u paste back the errors u encounter
thank you for ur reply.
i’ve tried the other prcedure which is just a little different from urs ( @ http://ns-2.blogspot.com/ ).everything went well yet i didnt find /ns/usr/bin/ns instead there is ns in the ns-2.34 directory itself.
i tried your sample code on it. the tcl script got executed but didnt get any simulation as output.tried to execute the .out file silmilar to the a.out file for a c program but didnt work.
i expect that the nam is not coordinating with tcl. can you help me make my ns2.34 work properly with out such headaches?
ty in advance
the following text is what i got when i run an example tcl script
root@ubuntu:/home/goldenchariot/simulator/ns-allinone-2.34/ns-2.34/tcl/ex# ns wireless-demo-csci694.tcl
num_nodes is set 3
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
INITIALIZE THE LIST xListHead
Loading connection pattern…
Loading scenario file…
Starting Simulation…
channel.cc:sendUp – Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
SORTING LISTS …DONE!
NS EXITING…
Thanks a lot!!!
nice bro, helpfull !
cannot find :
./validate
please help. Thanks.
when i run the software using the above step, it shown otcl make failed with 1 error.. how can i solve this problem??
yes i do have the seam problem can any one help please
i really need to make it work .thank you all in advance
bro…i got problem when i tried to simulate the wireless nodes
tiz is the error that i had discovered:
praving@ubuntu:~/Downloads$ ns wireless1.tcl
num_nodes is set 3
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
INITIALIZE THE LIST xListHead
Loading connection pattern…
couldn’t read file “../mobility/scene/cbr-3-test”: no such file or directory
while executing
“source.orig ../mobility/scene/cbr-3-test”
(“uplevel” body line 1)
invoked from within
“uplevel source.orig [list $fileName]”
invoked from within
“if [$instance_ is_http_url $fileName] {
set buffer [$instance_ read_url $fileName]
uplevel eval $buffer
} else {
uplevel source.orig [list $fileName]
…”
(procedure “source” line 8)
invoked from within
“source $val(cp)”
(file “wireless1.tcl” line 88)
praving@ubuntu:~/Downloads$ tcl/ex/wireless-mitf.tcl
bash: tcl/ex/wireless-mitf.tcl: No such file or directory
hi,
i m new to ns 2 . I have carried out installation and validation successfully but when i tried to write the following codes
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
I get command not found error for the $ns namtrace-all $nf. please someone help me.
thanks in advance
hey dude thanx a lotssss……..
i was messed up with these stuff since a week…..
can u guide me on how to compare adhoc routing protocols(dsdv,dsr and aodv) using ns2…pls….reply as early as possible coz a devil is behind us(our proffesor hahahahahah)
is this tutorial work with installing ns2.28? im kinda confuse now…tq
hi..
i’ve done all the steps ..even follow the extracting of ns2 in Desktop as mention on your entries..but the when it comes to step gedit ~./bashrc..i’ve copied ur program and change the host name but when to save the gedit file it mentions : “could not find the file /home/marlinee/Desktop/ns-allinone-2.34/~./bashrc. How to solve it? I’m surely it was an exact location of ns2 files.
save the file in your home folder say it should be in :
/home/host/.bashrc
or else open the file directly using nautilus->view->show hidden files
thanks a lot karthik!!..ur notes and entries such a good helps!
a BIG thanks..bro!
cannot find :
./validate
help me out……..
you have to type ./validate into this folder ../ns-allinone-2.34/ns-2.34 otherwise it won’t work.
Hi guys,
im using ubuntu 10.04, ns-2 version 2.34 and i really new with this ns2 and linux. im just wondering what went wrong when im running the example code given in this website. this is what i got after running the example code.
./myprog.tcl: line 6: namtrace-all: command not found
./myprog.tcl: line 9: proc: command not found
./myprog.tcl: line 10: global: command not found
./myprog.tcl: line 11: flush-trace: command not found
./myprog.tcl: line 13: close: command not found
./myprog.tcl: line 15: exec: nam: not found
really appreciate if anyone could explain to me what went wrong and another thing, for step 6 it says copy all and paste to /usr/bin/ directory. what happened if im not linking it with my /usr/bin directory?
thanks.
[...] Installing Network Simulator 2 in Ubuntu February 2010 19 comments and 1 Like on WordPress.com, 4 [...]
i got following error during installation …..
checking for main in -lXbsd… no
checking for connect… yes
checking for gethostbyname… yes
checking whether char is unsigned… no
updating cache ./config.cache
creating ./config.status
creating Makefile
creating tkConfig.sh
gcc -c -O2 -pipe -Wall -Wno-implicit-int -fno-strict-aliasing -fPIC -I/home/atul/ns-allinone-2.34/tk8.4.18/unix -I/home/atul/ns-allinone-2.34/tk8.4.18/unix/../generic -I/home/atul/ns-allinone-2.34/tk8.4.18/unix/../bitmaps -I/home/atul/ns-allinone-2.34/tcl8.4.18/generic -DHAVE_LIMITS_H=1 -DHAVE_UNISTD_H=1 -DSTATIC_BUILD=1 -DPEEK_XCLOSEIM=1 -D_LARGEFILE64_SOURCE=1 -DTCL_WIDE_INT_TYPE=long\ long -DHAVE_STRUCT_STAT64=1 -DHAVE_OPEN64=1 -DHAVE_LSEEK64=1 -DHAVE_TYPE_OFF64_T=1 -DHAVE_SYS_TIME_H=1 -DTIME_WITH_SYS_TIME=1 -DSTDC_HEADERS=1 -DHAVE_PW_GECOS=1 -DTCL_NO_DEPRECATED /home/atul/ns-allinone-2.34/tk8.4.18/unix/../generic/tk3d.c
In file included from /home/atul/ns-allinone-2.34/tk8.4.18/unix/../generic/tkInt.h:21,
from /home/atul/ns-allinone-2.34/tk8.4.18/unix/../generic/tk3d.h:18,
from /home/atul/ns-allinone-2.34/tk8.4.18/unix/../generic/tk3d.c:16:
/home/atul/ns-allinone-2.34/tk8.4.18/unix/../generic/tk.h:81:23: error: X11/Xlib.h: No such file or directory
In file included from /home/atul/ns-allinone-2.34/tk8.4.18/unix/../generic/tkInt.h:21,
from /home/atul/ns-allinone-2.34/tk8.4.18/unix/../generic/tk3d.h:18,
from /home/atul/ns-allinone-2.34/tk8.4.18/unix/../generic/tk3d.c:16:
tk8.4.18 make failed! Exiting …
plz help me….thanx
i got following error in installation in ubuntu 10.04
cloud@cloud-desktop:~/ns-allinone-2.34$ ./install
============================================================
* Testing for Darwin (OS X) environment
============================================================
============================================================
* Testing for Cygwin environment
============================================================
Cygwin not detected, proceeding with regular install.
============================================================
* Testing for FreeBSD environment
============================================================
FreeBSD not detected
============================================================
* Build XGraph-12.1
============================================================
loading cache ./config.cache
checking for a BSD compatible install… /usr/bin/install -c
checking whether build environment is sane… configure: error: newly created file is older than distributed files!
Check your system clock
make: *** No targets specified and no makefile found. Stop.
Can not create xgraph; But xgraph is an optional package, continuing…
============================================================
* Build CWeb
============================================================
Making cweb
make: Warning: File `Makefile’ has modification time 2.7e+08 s in the future
./ctangle ctangle
make: ./ctangle: Command not found
make: *** [ctangle.c] Error 127
cweb failed to make, but it’s optional
chmod: cannot access `cweave’: No such file or directory
chmod: cannot access `ctangle’: No such file or directory
ln: creating symbolic link `cweave’: File exists
ln: creating symbolic link `ctangle’: File exists
============================================================
* Build Stanford GraphBase
============================================================
Making sgb
make: Warning: File `Makefile’ has modification time 2.7e+08 s in the future
if test -r gb_io.ch; then ctangle gb_io.w gb_io.ch; else ctangle gb_io.w; fi
/bin/sh: ctangle: not found
make: *** [gb_io.c] Error 127
Unable to create sgb library, but it’s optional, so continuing…
============================================================
* Build GT-ITM
============================================================
sgb lib not found. gt-itm & sgb2ns could not be installed. Continuing..
============================================================
* Build zlib
============================================================
Checking for gcc…
Building static library libz.a version 1.2.3 with gcc.
Checking for unistd.h… Yes.
Checking whether to use vs[n]printf() or s[n]printf()… using vs[n]printf()
Checking for vsnprintf() in stdio.h… Yes.
Checking for return value of vsnprintf()… Yes.
Checking for errno.h… Yes.
Checking for mmap support… Yes.
make: Warning: File `example.c’ has modification time 2.7e+08 s in the future
gcc -O3 -DUSE_MMAP -c -o example.o example.c
gcc -O3 -DUSE_MMAP -c -o adler32.o adler32.c
gcc -O3 -DUSE_MMAP -c -o compress.o compress.c
^Z
[5]+ Stopped ./install
cloud@cloud-desktop:~/ns-allinone-2.34$ ./install
============================================================
* Testing for Darwin (OS X) environment
============================================================
============================================================
* Testing for Cygwin environment
============================================================
Cygwin not detected, proceeding with regular install.
============================================================
* Testing for FreeBSD environment
============================================================
FreeBSD not detected
============================================================
* Build XGraph-12.1
============================================================
loading cache ./config.cache
checking for a BSD compatible install… /usr/bin/install -c
checking whether build environment is sane… configure: error: newly created file is older than distributed files!
Check your system clock
make: *** No targets specified and no makefile found. Stop.
Can not create xgraph; But xgraph is an optional package, continuing…
============================================================
* Build CWeb
============================================================
Making cweb
make: Warning: File `Makefile’ has modification time 2.7e+08 s in the future
./ctangle ctangle
make: ./ctangle: Command not found
make: *** [ctangle.c] Error 127
cweb failed to make, but it’s optional
chmod: cannot access `cweave’: No such file or directory
chmod: cannot access `ctangle’: No such file or directory
ln: creating symbolic link `cweave’: File exists
ln: creating symbolic link `ctangle’: File exists
============================================================
* Build Stanford GraphBase
============================================================
Making sgb
make: Warning: File `Makefile’ has modification time 2.7e+08 s in the future
if test -r gb_io.ch; then ctangle gb_io.w gb_io.ch; else ctangle gb_io.w; fi
/bin/sh: ctangle: not found
make: *** [gb_io.c] Error 127
Unable to create sgb library, but it’s optional, so continuing…
============================================================
* Build GT-ITM
============================================================
sgb lib not found. gt-itm & sgb2ns could not be installed. Continuing..
============================================================
* Build zlib
============================================================
Checking for gcc…
Building static library libz.a version 1.2.3 with gcc.
Checking for unistd.h… Yes.
Checking whether to use vs[n]printf() or s[n]printf()… using vs[n]printf()
Checking for vsnprintf() in stdio.h… Yes.
Checking for return value of vsnprintf()… Yes.
Checking for errno.h… Yes.
Checking for mmap support… Yes.
make: Warning: File `example.c’ has modification time 2.7e+08 s in the future
gcc -O3 -DUSE_MMAP -c -o example.o example.c
gcc -O3 -DUSE_MMAP -c -o adler32.o adler32.c
gcc -O3 -DUSE_MMAP -c -o compress.o compress.c
gcc -O3 -DUSE_MMAP -c -o crc32.o crc32.c
gcc -O3 -DUSE_MMAP -c -o gzio.o gzio.c
gcc -O3 -DUSE_MMAP -c -o uncompr.o uncompr.c
gcc -O3 -DUSE_MMAP -c -o deflate.o deflate.c
gcc -O3 -DUSE_MMAP -c -o trees.o trees.c
gcc -O3 -DUSE_MMAP -c -o zutil.o zutil.c
gcc -O3 -DUSE_MMAP -c -o inflate.o inflate.c
gcc -O3 -DUSE_MMAP -c -o infback.o infback.c
gcc -O3 -DUSE_MMAP -c -o inftrees.o inftrees.c
gcc -O3 -DUSE_MMAP -c -o inffast.o inffast.c
ar rc libz.a adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o
gcc -O3 -DUSE_MMAP -o example example.o -L. libz.a
gcc -O3 -DUSE_MMAP -c -o minigzip.o minigzip.c
gcc -O3 -DUSE_MMAP -o minigzip minigzip.o -L. libz.a
make: warning: Clock skew detected. Your build may be incomplete.
Zlib has been installed successfully.
============================================================
* Build tcl8.4.18
============================================================
make: Warning: File `/home/cloud/ns-allinone-2.34/tcl8.4.18/unix/Makefile.in’ has modification time 2.7e+08 s in the future
/bin/sh config.status
creating Makefile
creating dltest/Makefile
creating tclConfig.sh
make: Warning: File `/home/cloud/ns-allinone-2.34/tcl8.4.18/unix/Makefile.in’ has modification time 2.7e+08 s in the future
/bin/sh config.status
creating Makefile
creating dltest/Makefile
creating tclConfig.sh
make: Warning: File `/home/cloud/ns-allinone-2.34/tcl8.4.18/unix/Makefile.in’ has modification time 2.7e+08 s in the future
/bin/sh config.status
creating Makefile
creating dltest/Makefile
creating tclConfig.sh
make: Warning: File `/home/cloud/ns-allinone-2.34/tcl8.4.18/unix/Makefile.in’ has modification time 2.7e+08 s in the future
/bin/sh config.status
creating Makefile
creating dltest/Makefile
creating tclConfig.sh
make: Warning: File `/home/cloud/ns-allinone-2.34/tcl8.4.18/unix/Makefile.in’ has modification time 2.7e+08 s in the future
/bin/sh config.status
creating Makefile