说明
本教程使用软件
node-v6.10.2-linux-x64.tar.xz
Node.js官网:https://nodejs.org/en/
下载地址:https://nodejs.org/dist/v6.10.2/node-v6.10.2-linux-x64.tar.xz
安装Node.js
下载Node.js到自己喜欢的目录下
wget https://nodejs.org/dist/v6.10.2/node-v6.10.2-linux-x64.tar.xz
解压
sudo tar xf node-v6.10.2-linux-x64.tar.xz
进入node bin目录 查看node版本
cd node-v6.10.2-linux-x64/
cd bin
./node -v
Node.js全局启动配置
这个时候发现只有在绝对路径下可以使用node,每次都要进入node-v6.10.2-linux-x64/bin目录来启动。需要将node配置到全局启动。以下两种方法都可以。(推荐使用注册环境变量)
进入node/bin查看当前绝对目录(以下是我的node目录)
pwd

1.注册环境变量
vi /etc/profile
在export PATH的上一行添加如下内容(绝对路径),然后保存退出。
PATH=$PATH:/www/node-v6.10.2-linux-x64/bin/

使变量生效
source /etc/profile
查看添加结果
echo $PATH
测试
node -v #查看node版本
npm -v #查看npm版本

2.软链接
添加软连接
ln -s /www/node-v6.10.2-linux-x64/bin/node /usr/local/bin/node #node.js
ln -s /www/node-v6.10.2-linux-x64/bin/npm /usr/local/bin/npm #npm
测试
node -v #查看node版本
npm -v #查看npm版本

网友评论