# ns2安裝
[安裝包](https://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz/download)
tar xvfz ns-allinone-2.35.tar.gz
cd ns-allinone-2.35
---------------
**Step 1:** Install the basic libraries like
$] sudo apt install build-essential autoconf automake libxmu-dev
**Step 2:** install gcc-4.8 and g++-4.8 **(要用這個版本跑才不會出錯)**
open the file using sudo mode
$] sudo nano /etc/apt/sources.list
Include the following line
deb http://in.archive.ubuntu.com/ubuntu bionic main universe
$] sudo apt update
$] sudo apt install gcc-4.8 g++-4.8
**Step 3:**
Unzip the ns2 packages to home folder
$] tar zxvf ns-allinone-2.35.tar.gz
$] cd ns-allinone-2.35/ns-2.35
Modify the following make files.
~ns-2.35/Makefile.in
Change @CC@ to gcc-4.8
change @CXX@ to g++-4.8
~nam-1.15/Makefile.in
~xgraph-12.2/Makefile.in
~otcl-1.14/Makefile.in
Change in all places
@CC@ to gcc-4.8
@CPP@ or @CXX@ to g++-4.8
open the file:
~ns-2.35/linkstate/ls.h
Change at the Line no 137
void eraseAll() { erase(baseMap::begin(), baseMap::end()); }
to This
void eraseAll() { this- erase(baseMap::begin(), baseMap::end()); }
All changes made
**Step 4:** Open a new terminal
$] cd ns-allinone-2.35/
$] ./install
**Step 5** - Set the PATH
vim ~/.bashrc

(下放圖片已經更新到上面的圖中)
source ~/.bashrc
完成後輸入ns出現%即表示安裝成功
測試:cd ns2/ns-2.35/tcl/ex
ns simple.tcl
## nam安裝
cd /usr/local/ns2/nam-1.15
./configure
make
sudo make install
如果有問題試試看:
sudo ./configure --with-tcl=/home/wengjiahuang/ns-allione-2.35/tcl8.5.10 --with-tcl-ver=8.5.10 --with-tk=/home/wengjiahuang/ns-allione-2.35/tk8.5.10 --with-tk-ver=8.5.10
---------------
[NS2安装及入门实例——(ns2.35 / Ubuntu20.04)(這很有用)](https://blog.csdn.net/WZRbeliever/article/details/132603271)
[參考安裝教學影片](https://www.youtube.com/watch?v=DiAqKK28Qn0)