我试图用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而不丢失全局安装包的前缀?


当前回答

I just have a idea. Use the symbolic link to solve the error and you can still use your prefix for globally installed packages. ln -s [your prefix path] [path in the '~/.nvm'] then you will have a symbolic folder in the ~/.nvm folder, but in fact, your global packages are still installed in [your prefix path]. Then the error will not show again and you can use nvm use ** normally. ps: it's worked for me on mac. pps: do not forget to set $PATH to your npm bin folder to use the globally installed packages.

其他回答

删除并重置字冠

$ npm config delete prefix 
$ npm config set prefix $NVM_DIR/versions/node/v6.11.1

注意:将版本号更改为错误消息中指示的版本号。

NVM不兼容NPM配置“prefix”选项:目前 set to "/usr/local"执行"npm config delete prefix"或"nvm use " ——delete-prefix v6.11.1——silent"


@gabfiocchi在Github -“你需要覆盖nvm前缀”

I just have a idea. Use the symbolic link to solve the error and you can still use your prefix for globally installed packages. ln -s [your prefix path] [path in the '~/.nvm'] then you will have a symbolic folder in the ~/.nvm folder, but in fact, your global packages are still installed in [your prefix path]. Then the error will not show again and you can use nvm use ** normally. ps: it's worked for me on mac. pps: do not forget to set $PATH to your npm bin folder to use the globally installed packages.

对于那些第一次通过自制程序安装node,然后将nvm添加到系统中的用户。

如果你看到嘈杂的消息:nvm不兼容npm配置“prefix”选项:当前设置为“/usr/local”,你可能需要删除node_modules和节点本身,解决方案在上面^^有完美的描述,但下面是简单的方法。

由于brew自动将env var添加到.bash_profile中,每次bash加载路径都指向最初安装的版本。

1.进入。/.bash_profile 2. 注释指向节点的行,如下所示 # =出口路径“/ usr /地方/ opt / node@10 / bin:美元路径”

下次bash应该加载nvm安装的节点, 确保bash_profile包含NVM dir 出口NVM_DIR = " /用户/ {your_user_name} / .nvm”

我也有同样的问题,每次使用终端都很烦人。我向终端运行命令,它被修复了

对于那些试图从brew中删除nvm的人

仅仅酿造卸载NVM可能是不够的

如果您看到NPM prefix仍然是/usr/local,请执行此命令

Sudo rm -rf /usr/local/ {lib /节点{/ .npm _modules},垃圾桶,分享/人}/ {npm *,节点*,男士一/节点*}

我有同样的问题,执行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会导致终端启动缓慢。您可以按照此说明来解决该问题。