这可能是一个新手问题,但我想知道为什么当我使用 nvm 安装节点时,它仅适用于该用户(它不是“全局”)。
假设我使用用户“admin”登录服务器:
curl https://raw.githubusercontent.com/creationix/nvm/v0.7.0/install.sh | sh
source ~/.profile
nvm install 0.10.30
nvm use 0.10.30
node -v
# outputs v0.10.30
该用户的节点已启动并正在运行,但是当我切换到根目录时:
su
node -v
显示:
The program 'node' can be found in the following packages:
* node
* nodejs-legacy
Try: apt-get install <selected package>
这是为什么呢?有没有办法安装节点并使其可供所有用户使用? (我不想每次新用户需要时都重新安装。)
问题是 NVM 将 node.js 安装到用户的本地目录,并更新该用户的 .profile。
这是一个一行脚本,可以将您的安装复制到 /usr/local/bin,每个人都可以在其中使用 node.js:
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local