Already this blog posts various titles on installing NS2 in Linux distros. Here is the step for installing in Ubuntu 11.04.
1. Version taken is NS2.34
2. Since ubuntu 11.04 uses GCC-4.5.2, there should be some minor tweeks.
3. Two files should be edited ~ns-2.34/tools/ranvar.cc and ~ns-2.34/mobile/nakagami.cc as given in the following post
4. Install the following things in Ubuntu
sudo apt-get install build-essential autoconf automake libxmu-dev
sudo apt-get install gcc-4.4
5. open the file ~ns-2.34/otcl-1.13/configure and change the line number 6304 to SHLIB_LD=”gcc -shared” instead of SHLIB_LD=”ld -shared”
6. open the file ~ns-2.34/otcl-1.13/Makefile.in and change the line CC @CC@ to CC gcc-4.4
7. Set the path in /home/<name>/ .bashrc as in http://www.pradeepkumar.org/installing-ns2-under-ubuntu-910.html
8. After setting the path, sometimes overflow error may come when running ns and nam, so open the file ~ns-2.34/tcl8.X.x/unix/Makefile.in and in line number 270 change @CC@ to @CC@ –V 4.4
Thats it!!! NS2 Installed.