ubuntu安装nodejs

1 node源码下载

https://nodejs.org/dist/v8.9.2/node-v8.9.2-linux-x64.tar.xz

2 所有的操作都需要超级权限,所以解压语句为

cd /home/flq1/Downloads && sudo tar xf node-v8.9.2-linux-x64.tar.xz -C /usr/local/

执行完上面的命令程序安装路径在 /usr/local/node-v8.9.2-linux-x64/bin

3:新建文件

vim /etc/profile.d/node.sh  

增加这一条 export PATH=$PATH:/usr/local/node-v8.9.2-linux-x64/bin

4 这是设置环境变量,然后 执行 source /etc/profile 使环境变量生效
which node 一下就看到node安装的目录。node -version可以查看node的版本

如果只是安装的话就结束了。监于每次安装都是遇到麻烦,知其然不知其所以然,我们再来分析一下里面的文件结构

flq1@ubuntu:/usr/local/node-v8.9.2-linux-x64/bin$ tree /etc/ |grep profile
│   │   │   ├── change_profile
│   └── profile
├── profile
├── profile.d
│   │   ├── 65compiz_profile-on-session
│   │   ├── a11y-profile-manager-indicator-autostart.desktop

在/etc/下面有一个文件profile和一个目录profile.d ,profile里面定义这个规则

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

是检测目录profile.d下面的*.sh文件,然后加载的

/etc/profile.d/
├── bash_completion.sh
├── cedilla-portuguese.sh
└── node.sh

我们在执行source /etc/profile的时候是把/etc/profile.d/下面的所有文件设置的环境变量加载进来了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值