[node.js] nvm is not compatible with the npm config "prefix" option:

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" option: 
   currently set to "/Users/z/.npm-global"
Run `npm config delete prefix` or `nvm use --delete-prefix v4.2.4` to unset it.

I have my prefix set on purpose to avoid sudo npm (see https://docs.npmjs.com/getting-started/fixing-npm-permissions).

Is there any way I can use nvm without losing my prefix for globally installed packages?

This question is related to node.js npm prefix nvm

The answer is


Note:
to remove, delete, or uninstall nvm - just remove the $NVM_DIR folder (usually ~/.nvm)
you can try :
rm -rf ~/.nvm


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:

  1. remove node_modules sudo rm -rf /usr/local/lib/node_modules
  2. remove node sudo rm /usr/local/bin/node
  3. remove node link cd /usr/local/bin && ls -l | grep "../lib/node_modules/" | awk '{print $9}'| xargs rm

After you cant install nvm


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.


I have the same error message but other solution. The autogenerated path during curl (install.sh) does not match. Check this with:

echo $NVM_DIR

In my case: /var/www//.nvm. Show in your auto generated bash file and change it and replace it: (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc)

replace

export NVM_DIR="$HOME/.nvm"

with (e.g.)

export NVM_DIR="$HOME.nvm"

enter image description hereI 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*}


Just resolved the issue. I symlinked $HOME/.nvm to $DEV_ZONE/env/node/nvm directory. I was facing same issue. I replaced NVM_DIR in $HOME/.zshrc as follows

export NVM_DIR="$DEV_ZONE/env/node/nvm"

BTW, please install NVM using curl or wget command not by using brew. For more please check the comment in this issue on Github: 855#issuecomment-146115434


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.


I followed https://stackoverflow.com/a/47861348/2391795 answer but it didn't work out well.

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

After running the recommended commands my nvm didn't work anymore, running nvm use would display the proper node version being used, but running node -v would show another. It wasn't possible to change node's version anymore.

I uninstalled and reinstalled nvm entirely to fix it. I followed https://github.com/creationix/nvm#manual-uninstall by running

$ rm -rf "$NVM_DIR"

Then edited my .zshrc to remove the lines related to nvm, which in my case were

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

Then started a new shell (so that nvm isn't loaded in this new shell) and ran https://github.com/creationix/nvm#install-script

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash

Which added nvm the lines I previously had removed in my .zshrc.

Then I was able to use nvm as I used to. I guess that's an odd case were things went wrong and forced me to reinstall everything, doesn't look like most people go through this due to this issue.


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

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.


I ran into this while using node installed via nvm, with nvm installed via homebrew. I solved it by running brew uninstall nvm, rm -rf $NVM_DIR, then reinstalling nvm using the official install script and reinstalling the node version I needed.

Note: I also had $NVM_DIR mounted and symlinked. I moved it back into my homedir.


I was looking for a solution for the nvm prefix problem a found this question(before finding the solution). Here is my shell "dialog". I hope, it can be usefull for somebody. I was able to set to prefix with the help of this post: https://github.com/npm/npm/issues/6592

When I tried npm config delete prefix or nvm use --delete-prefix before using npm --prefix="" set prefix "", I got only: npm ERR! not ok code 0

Note that you will have to repeat the same procedure with every node version, the prefix is set back to (in my case) /usr/local after installation.

    $ nvm install 0.10
    ######################################################################## 100.0%
    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 v0.10.44` to unset it.
    $ npm --prefix="" set prefix ""
    $ nvm use 0.10.44
    nvm is not compatible with the npm config "prefix" option: currently set to "/home/john"
    Run `npm config delete prefix` or `nvm use --delete-prefix v0.10.44` to unset it.
    $ nvm use --delete-prefix v0.10.44
    Now using node v0.10.44 (npm v1.3.10)
    $ nvm ls
    v0.10.44
             v4.4.3
    ->       system
    default -> 4.4.3 (-> v4.4.3)
    node -> stable (-> v4.4.3) (default)
    stable -> 4.4 (-> v4.4.3) (default)
    iojs -> N/A (default)
    $ npm config get prefix
    /usr/local

I had this issue after moving my home folder to a new drive on linux. It was fixed by removing .nvm folder and reinstalling nvm


I solved this problem when it was showing on VSCode and JetBrains Terminals, but not in the native terminal using the following commands:

ls -la /usr/local/bin | grep "np[mx]"

This will give you the resolved path at the end:

... npm -> ../lib/node_modules/npm/bin/npm-cli.js
... npx -> ../lib/node_modules/npm/bin/npx-cli.js

From there, removing the files and relaunching VS Code should fix the issue:

rm -R /usr/local/bin/npm /usr/local/lib/node_modules/npm/bin/npm-cli.js
rm -R /usr/local/bin/npx /usr/local/lib/node_modules/npm/bin/npx-cli.js

fix link: https://github.com/nvm-sh/nvm/issues/1690#issuecomment-392014774


This error can occur when your NVM installation folder path has a Symbolic Link.

Explanation

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.

Solution

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"

Examples related to node.js

Hide Signs that Meteor.js was Used Querying date field in MongoDB with Mongoose SyntaxError: Cannot use import statement outside a module Server Discovery And Monitoring engine is deprecated How to fix ReferenceError: primordials is not defined in node UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac internal/modules/cjs/loader.js:582 throw err DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean`

Examples related to npm

What does 'x packages are looking for funding' mean when running `npm install`? error: This is probably not a problem with npm. There is likely additional logging output above Module not found: Error: Can't resolve 'core-js/es6' Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.1 was found instead DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean` What exactly is the 'react-scripts start' command? On npm install: Unhandled rejection Error: EACCES: permission denied Difference between npx and npm?

Examples related to prefix

nvm is not compatible with the npm config "prefix" option: Rename multiple files in a folder, add a prefix (Windows) Linux configure/make, --prefix? conversion from infix to prefix How to rename with prefix/suffix?

Examples related to nvm

How can the default node version be set using NVM? How to properly upgrade node using nvm nvm is not compatible with the npm config "prefix" option: Node Version Manager (NVM) on Windows nvm keeps "forgetting" node in new terminal session Node Version Manager install - nvm command not found