我试图用nvm运行另一个NodeJS版本,但得到这个错误:
$ nvm use v4.2.4
nvm is not compatible with the npm config "prefix" option:
currently set to "/Users/z/.npm-global"
Run `npm config delete prefix` or `nvm use --delete-prefix v4.2.4` to unset it.
我特意设置了前缀,以避免sudo npm(参见https://docs.npmjs.com/getting-started/fixing-npm-permissions)。
是否有任何方法可以使用nvm而不丢失全局安装包的前缀?
我有同样的问题,执行npm config delete prefix没有帮助我。
但这确实起了作用:
使用brew安装nvm后,创建~/。nvm目录:
$ mkdir ~/.nvm
并在~/.bash_profile中添加以下行:
export NVM_DIR=~/.nvm
. $(brew --prefix nvm)/nvm.sh
(检查在~/中没有其他与nvm相关的命令。Bashrc或~/。Profile或~/.bash_profile)
打开一个新终端,这次它应该不会打印任何警告消息。
执行nvm——version命令检查nvm是否正常工作。
然后,使用nvm install node && nvm alias default node安装/重新安装NodeJS。
更多信息
我用自制程序安装了nvm,之后我收到了这个通知:
Please note that upstream has asked us to make explicit managing
nvm via Homebrew is unsupported by them and you should check any
problems against the standard nvm install method prior to reporting.
You should create NVM's working directory if it doesn't exist:
mkdir ~/.nvm
Add the following to ~/.bash_profile or your desired shell
configuration file:
export NVM_DIR=~/.nvm
. $(brew --prefix nvm)/nvm.sh
You can set $NVM_DIR to any location, but leaving it unchanged from
/usr/local/Cellar/nvm/0.31.0 will destroy any nvm-installed Node installations
upon upgrade/reinstall.
忽略它让我看到了这个错误消息:
nvm不兼容npm配置的“prefix”选项:当前设置为“/usr/local/Cellar/nvm/0.31.0/versions/node/v5.7.1”
执行nvm use——delete-prefix v5.7.1——silent命令取消设置。
我遵循了之前的指南(来自homebrew/nvm),之后我发现我需要重新安装NodeJS。于是我做了:
nvm install node && nvm alias default node
它是固定的。
更新:
使用brew安装NVM会导致终端启动缓慢。您可以按照此说明来解决该问题。