I had the same problem and executing npm config delete prefix
did not help me.
But this did:
After installing nvm using brew, create ~/.nvm
directory:
$ mkdir ~/.nvm
and add following lines into ~/.bash_profile
:
export NVM_DIR=~/.nvm
. $(brew --prefix nvm)/nvm.sh
(Check that you have no other nvm related command in any ~/.bashrc
or ~/.profile
or ~/.bash_profile
)
Open a new terminal and this time it should not print any warning message.
Check that nvm is working by executing nvm --version
command.
After that, install/reinstall NodeJS using nvm install node && nvm alias default node
.
More Info
I installed nvm
using homebrew
and after that I got this notification:
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.
Ignoring it brought me to this error message:
nvm
is not compatible with the npm config
"prefix" option: currently set to "/usr/local/Cellar/nvm/0.31.0/versions/node/v5.7.1"
Run nvm use --delete-prefix v5.7.1 --silent
to unset it.
I followed an earlier guide (from homebrew/nvm
) and after that I found that I needed to reinstall NodeJS. So I did:
nvm install node && nvm alias default node
and it was fixed.
Update:
Using brew to install NVM causes slow startup of the Terminal. You can follow this instruction to resolve it.
nvm
could manage the installs as you point. However, it looks like it fails to do so by itself, asking me instead to delete my prefix. Why can't thenvm
simply override that setting as long as it is active? So thenvm
would use its own settings, and I can keep my previous working state when I exitnvm
to return to my regular node version. – Deoxyribosenvm
would replace the current node and thenpm
for the chosen version withnvm use <version>
. Then the newnpm
would have its own setting, a sort of "override" but better ;). That way, the newnpm
would not even "know" about the old prefix, so the problem shouldn't even exist. Or does thenvm
only replace the node but keeps the oldnpm
(which would be confusing imo)? I was also assuming the switch to selected node version was not per-shell, was it? – Deoxyribosenpm root -g
) is located inside your HOME directory - which you don't need sudo to modify. Separately, the ecosystem at large strongly discourages installing ANYTHING globally, so this problem shouldn't really pop up in modern usage anyways. – Malfeasance