For those who are unaware of NS2, NS2 is a event-driven network simulation software, used to study network models and simulate network scenarios. Installation of NS2 in Ubuntu seems like a tough job for many. If not, atleast for me, it was a herculean task because of lesser documentation on this installation part.

Network Simulator

Without much talking, lets dive into the topic.

Since “long long ago so long ago”, this has been the method of installation. But installing in latest version of Ubuntu is little challenging due to the new gcc version.

Step 1 : Install the dependencies

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

Step 2 : Download ns-allinone-2.35 package from NS2 official site. At the time of this writing, the latest version was 2.35 RC7.

Step 3 : Place the ns-allinone-2.35.tar.gz file in your home folder(/home/sunshadow in my case). Extract the contents of the archive to a folder of the same name.

Step 4 : Open terminal and change directory to the ns folder.

     $ cd /home/sunshadow/ns-allinone-2.34
Step 5 : Editing files to remove X::X construct – Edit the file ns-2.35/tools/ and change the line 219 :

return GammaRandomVariable::GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);
return GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);

Similarly, change the lines 183 and 185 in file ns-2.34/mobile/ :
resultPower = ErlangRandomVariable(Pr/m, int_m).value();
resultPower = GammaRandomVariable(m, Pr/m).value();

Step 6: Begin ns2.35 installation

     $ sudo su

     $ ./install

The installation runs for a couple of minutes. Don’t get freaked out on seeing the varieties of warnings and messages over there. :P. Its normal. Don’t close this terminal. We got some important information in the last section of the installation.

Step 7 : Add the path information to the file ~/.bashrc

     $ gedit ~/.bashrc

Append the following lines to the file ~/.bashrc

export PATH=$PATH:/home/narendran/Documents/ns-allinone-2.35-RC7/bin:/home/narendran/Documents/ns-allinone-2.35-RC7/tcl8.5.8/unix:/home/narendran/Documents/ns-allinone-2.35-RC7/tk8.5.8/unixexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/narendran/Documents/ns-allinone-2.35-RC7/otcl-1.14:/home/narendran/Documents/ns-allinone-2.35-RC7/libexport TCL_LIBRARY=$TCL_LIBRARY:/home/narendran/Documents/ns-allinone-2.35-RC7/tcl8.5.8/library

Here replace /home/narendran/Documents with the path to your home folder.

Step 8 : Check installation : Thats it, folks!! Now type ns in terminal. A ‘%’ symbol will be displayed denoting that interpreter is working. Installation Success!!

Happily Ever After 🙂

Note : If you are not a serious ns developer or you just want to run a simulation file on your system, use apt-get or yum (based on which Linux distro you use) Eg. : sudo apt-get install ns2 nam xgraph. It is not mandatory to build ns2 from source to use it.