I am trying to run another NodeJS version with nvm
but getting this error:
$ nvm use v4.2.4
nvm is not compatible with the npm config \"prefix\
It might be the problem if you have your home directory mounted somewhere, due nvm does not work properly with symlinks. Because I don't care where is my $NVM_DIR located I run this and all works fine:
$ mv ~/.nvm /tmp/
$ export NVM_DIR="/tmp/.nvm"
$ nvm use --delete-prefix v6.9.1
$ npm config delete prefix
$ npm config set prefix $NVM_DIR/versions/node/v6.11.1
Note: Change the version number with the one indicated in the error message.
nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local" Run "npm config delete prefix" or "nvm use --delete-prefix v6.11.1 --silent" to unset it.
Credits to @gabfiocchi on Github - "You need to overwrite nvm prefix"
Let me describe my situation.
First, check the current config
$ nvm use --delete-prefix v10.7.0
$ npm config list
Then, I found the error config in output:
; project config /mnt/c/Users/paul/.npmrc
prefix = "/mnt/c/Users/paul/C:\\Program Files\\nodejs"
So, I deleted the C:\\Program Files\\nodejs
in /mnt/c/Users/paul/.npmrc.
This may be a conflict with your local installation of Node (if you had it installed via another way than NVM in the past). You should delete this instance of node:
sudo rm -rf /usr/local/lib/node_modules
sudo rm /usr/local/bin/node
cd /usr/local/bin && ls -l | grep "../lib/node_modules/" | awk '{print $9}'| xargs rm
After you cant install nvm
This error can occur when your NVM installation folder path has a Symbolic Link.
The default installation path of NVM is: $HOME/.nvm
but your home folder could be a symbolic link for another drive, like my case.
Example, my home folder is a Symbolic Link to aother drive:
/home/myuser -> /bigdrive/myuser
This cause the prefix problem.
On your startup script (.bashrc or .zshrc or other), change the NVM folder to the direct path.
Ex: NVM_DIR="/bigdrive/myuser/.nvm"
.
.bashrc
export NVM_DIR="/bigdrive/myuser/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
I had the same problem and it was really annoying each time with the terminal. I run the command to the terminal and it was fixed
For those try to remove nvm from brew
it may not be enough to just brew uninstall nvm
if you see npm prefix is still /usr/local, run this command
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}