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


当前回答

以下是我所做的工作

1- sudo su

2-root@antonio:/home/antonio# mv ~/.nvm /tmp/

3- root@antonio:/home/antonio# export NVM_DIR=“/tmp/.nvm”

4- root@antonio:/home/antonio# NVM使用——delete-prefix v17.4.0

5- ' root@antonio:/home/antonio# node -v

`

其他回答

我也遇到过同样的问题,这是因为node和nodejs的npm冲突

因此,通过以下命令删除nodejs

sudo apt-get remove nodejs

这将删除所有与nodejs相关的包,

在上面的命令之后,您必须运行autoremove命令

sudo apt autoremove

这样问题就解决了,

我在把我的主文件夹移动到linux上的新驱动器后遇到了这个问题。通过删除.nvm文件夹并重新安装nvm来修复

如果你把你的主目录挂载在某个地方,这可能是一个问题,因为nvm不能正确地使用符号链接。因为我不关心我的$NVM_DIR位于哪里,我运行这个,一切正常:

$ mv ~/.nvm /tmp/
$ export NVM_DIR="/tmp/.nvm"
$ nvm use --delete-prefix v6.9.1

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.

我试过了这篇文章里的每一个答案,但没有一个奏效。重新安装nvm文档https://github.com/nvm-sh/nvm与curl修复了我的问题。