The "build prerequisites" for ns2 must be installed :
sudo apt install g++ g++-4.8 autoconf libtool libxmu-dev
Unpack a new ns-allinone into a new folder in /home/name/
tar xvf ns-allinone-2.35_gcc5.tar.gz ## 2014 - 2017 update
cd ns-allinone-2.35/
export CC=gcc-4.8 CXX=g++-4.8 && ./install
cd ns-2.35/
sudo make install ## will copy the executable ns to /usr/local/bin/
cp ns ns-orig ## this is your backup of the stock ns / the unmodified executable
sudo cp ns-orig /usr/local/bin/