在ubuntu上安装ns2和nam(ubuntu16.04)

在ubuntu上安装ns2和nam

版本选择

首先,版本的合理选择可以让我们避免很多麻烦

经过测试,ubuntu的版本选择为ubuntu16.04,ns2的版本选择为ns-2.35,nam包含于ns2

资源链接(百度网盘)

链接:https://pan.baidu.com/s/1LMB3DPFlCLqvafDAtyYYXg?pwd=8888

提取码:8888

安装ns2

首先,安装好对应的ubuntu版本后,先对系统的相关项进行更新

· 复制代码
sudo apt-get  update #更新源列表
sudo apt-get upgrade #更新已经安装的包

如果觉得速度太慢的话,可以更换国内源
编辑/etc/apt/sources.list文件

添加在代码最前面,任选其一即可
清华源

· 复制代码
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

阿里源

复制代码
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
```

**中科大源**

```·
deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
```

重新加载下资源

```·
source /etc/apt/sources.list
```

更新源

```·
sudo apt-get update
```

**下载相关依赖**

```·
sudo apt-get install build-essential
sudo apt-get install tcl8.5 tcl8.5-dev tk8.5 tk8.5-dev  #for tcl and tk
sudo apt-get install libxmu-dev libxmu-headers  #for nam
```

**安装ns2**

```·
tar xvfz ns-allinone-2.35.tar.gz -C /opt
cd /opt/ns-allinone-2.35
./install #进行安装
```

安装可能会报以下错:

```·
linkstate/ls.h:137:20: note: use 'this->erase' instead
make: *** [linkstate/ls.o] Error 1
Ns make failed!
```

解决:  

修改ls文件:ns-2.35/linkstate/ls.h 第137行  

将 void eraseAll() { erase(baseMap::begin(), baseMap::end()); }  

改为:

```·
void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }
```

保存后 ./install 即可  
**配置环境变量**

```·
gedit  ~/.bashrc
```

末尾添加以下内容(注意修改路径)

```·
#add path for ns2
export NS_HOME=/opt/ns-allinone-2.35 
export PATH=$PATH:$NS_HOME/bin:$NS_HOME/tcl8.5.10/unix:$NS_HOME/tk8.5.10/unix
export LD_LIBRARY_PATH=$NS_HOME/otcl-1.14:$NS_HOME/lib  
export TCL_LIBRARY=$NS_HOME/tcl8.5.10/library
```

**验证ns2安装**   

输入ns,出现%,说明ns2安装成功

# 安装nam

进入nam目录:

```·
cd /opt/ns-allinone-2.35/nam-1.15
```

运行配置

```·
sudo ./configure
```

这里可能会出现以下错误:

    configure: error: Installation of tcl seems incomplete or can't be found automatically.
    Please correct the problem by telling configure where tcl is
    using the argument --with-tcl=/path/to/package
    (perhaps after installing it),
    or the package is not required, disable it with --with-tcl=no.

指定版本号即可

```·
sudo ./configure --with-tcl-ver=8.5
```

更新nam

```·
sudo make
```

最后

```·
sudo make install
```

最后这里可能会出现

    /usr/bin/install -c -m 755 nam /usr/local/bin

运行即可

```·
sudo /usr/bin/install -c -m 755 nam /usr/local/bin
```

命令行输入nam弹出nam console说明nam安装成功  
**运行测试**

cd /opt/ns-allinone-2.35/ns-2.35/tcl/ex/
ns simple.tcl

复制代码
运行时可能会出现以下问题  
![在这里插入图片描述](https://file.jishuzhan.net/article/1698968534165491714/f259055789204fcfb771433e3e79ed03.png)

解决:权限放开

```·
sudo chmod  777 out.tr

解决:权限放开

· 复制代码
sudo chmod  777 out.nam

运行结果:

相关推荐
jim写博客11 分钟前
Linux进程概念(四)环境地址变量
linux·运维·服务器
稚辉君.MCA_P8_Java17 分钟前
豆包 Java的23种设计模式
java·linux·jvm·设计模式·kubernetes
Nie_Xun1 小时前
ubuntu网络共享
linux·运维·ubuntu
花小璇学linux2 小时前
imx6ull-驱动开发篇22——Linux 时间管理和内核定时器
linux·运维·驱动开发
你好,赵志伟3 小时前
Socket 编程 TCP
linux·服务器·tcp/ip
Liang_GaRy4 小时前
心路历程-三个了解敲开linux的大门
linux·运维·服务器
一只栖枝8 小时前
华为 HCIE 大数据认证中 Linux 命令行的运用及价值
大数据·linux·运维·华为·华为认证·hcie·it
wuicer10 小时前
ubuntu 20.04 安装anaconda以及安装spyder
linux·运维·ubuntu
cpsvps_net11 小时前
美国服务器环境下Windows容器工作负载智能弹性伸缩
windows
甄超锋12 小时前
Java ArrayList的介绍及用法
java·windows·spring boot·python·spring·spring cloud·tomcat