Step 1: Download the source for NS2 all in one (I used this version ns-allinone-2.34.tar.gz ) from the link http://sourceforge.net/projects/nsnam/files/
Step 2: Extract the tar.gz file downloaded into your home folder by right-clicking the tag.gz file
Step 3: Open terminal (Applications-->Accessories-->Terminal) and change the directory (using cd command) to the extracted folder and execute the following:
sudo apt-get install build-essential autoconf automake libxmu-dev
This will install the dependencies required to compile NS2 from the source.
The following command is used to compile the source.
./install
It will take long time to compile all the required packages for ns to work...
Step 4: Setting Environmental Variables
Type in terminal:
gedit ~/.bashrc
and append the following text to the opened file (Please note that the path contains the path in my system, replace "venkat" in path with your username)
# LD_LIBRARY_PATH
OTCL_LIB=/home/venkat/ns-allinone-2.34/otcl-1.13
NS2_LIB=/home/venkat/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/venkat/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB# PATH
XGRAPH=/home/venkat/ns-allinone-2.34/bin:/home/venkat/ns-allinone-2.34/tcl8.4.18/unix:/home/venkat/ns-allinone-2.34/tk8.4.18/unix
NS=/home/venkat/ns-allinone-2.34/ns-2.34/
NAM=/home/venkat/ns-allinone-2.34/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM
Step 5: Now, after editing the file, save and close it. Then in terminal type:
source ~/.bashrc
Try "ns" command, it shud go to the "%" prompt then it just means the installation was successful! Enjoy :D
Note: These steps have been tested and worked like breeze in Ubuntu and is expected work in all the debian based linux.
Reference:
1.) http://nsnam.isi.edu/nsnam/index.php/Installing_ns2.31_on_Ubuntu7.04
2.) http://alkautsarpens.wordpress.com/2008/02/05/install-ns231-for-ubuntu-gutsy-710/
3.) http://www.isi.edu/nsnam/ns/ns-build.html (Might not be needing this, but just in case)
and append the following text to the opened file (Please note that the path contains the path in my system, replace "venkat" in path with your username)



Installation
