无法从根目录(或sudo)使用NVM [英] Can't use NVM from root (or sudo)
问题描述
我已经提到我的应用程序从sudo
运行时使用了不同版本的NodeJS.
I've mentioned that my application uses different version of NodeJS when running from sudo
.
$ node -v
v0.10.23
$ sudo node -v
v0.11.8-pre
此 v0.11.8-pre 给我带来了一些问题,所以我绝对不想使用它,但无法将其更改为root.
This v0.11.8-pre caused me some problems, so I definitely don't want to use it, but I can't change it for root.
$ sudo nvm use v0.10.23
sudo: nvm: command not found
我尝试从root用户安装nvm,但出现错误已安装NVM",但从sudo
运行时仍找不到nvm.我怎么了?
I've tried to install nvm from root user, but got error "NVM already installed", but still nvm not found when running from sudo
. What is my problem?
推荐答案
The below list of commands (source: digitalocean) seems to fix the problem
n=$(which node); \
n=${n%/bin/node}; \
chmod -R 755 $n/bin/*; \
sudo cp -r $n/{bin,lib,share} /usr/local
上面的命令有点复杂,但是它所做的就是将通过nvm激活的任何版本的节点复制到/usr/local/
目录(用户安装的全局文件应位于Linux VPS上)并设置权限,以便所有用户都可以访问它们.
The above command is a bit complicated, but all it's doing is copying whatever version of node you have active via nvm into the /usr/local/
directory (where user installed global files should live on a linux VPS) and setting the permissions so that all users can access them.
希望这会有所帮助!
这篇关于无法从根目录(或sudo)使用NVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!