• Register
0 votes

Problem :

 I want to to run my NodeJS version with the nvm but getting following 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 set the prefix on purpose to avoid the sudo npm 

How can I use nvm without losing the prefix for my globally installed packages?

6 5 3
7,540 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I faced this issue while trying to use the node installed via nvm, and nvm installed via the homebrew. I solved the issue by running following command:

 brew uninstall nvm, rm -rf $NVM_DIR,

then reinstalled the nvm by using the official install script and after that reinstalling my node version which I needed.

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


It can cause you the big problem if you are having your HomeDir mounted somewhere else, and because of this your nvm will not work properly with the symlinks. As I never bothered where my $NVM_DIR located so I simply ran following commands and all is works fine for me :

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

9 7 4
38,600 points
0 votes


Delete and Reset the prefix

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

Note: alter the version number with the one indicated in the error message.

nvm is not compatible with the npm config "prefix" option: presently set to "/usr/local" Run "npm config delete prefix" or "nvm use --delete-prefix v6.11.1 --silent" to unset it.

After installing nvm employing brew, create ~/.nvm directory:
$ mkdir ~/.nvm

and include following lines into ~/.bash_profile:

export NVM_DIR=~/.nvm
. $(brew --prefix nvm)/nvm.sh

(inspect that you have no other nvm concerned command in any ~/.bashrc or ~/.profile or ~/.bash_profile)

Open a new terminal and this time it must not print any warning message.
Inspect that nvm is performing by executing nvm --version command.
After that, install/reinstall NodeJS employing nvm install node && nvm alias default node.

More Info

I installed nvm employing homebrew and after that I got this notification:

Please note that upstream has asked us to create explicit managing nvm through Homebrew is unsupported by them and you must check any problems against the standard nvm install method before to reporting.

You must make NVM's working directory in case it doesn't exist:

mkdir ~/.nvm

Include 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, however leaving it unchanged from /usr/local/Cellar/nvm/0.31.0 will destroy any nvm-installed Node installations upon upgrade/reinstall.

Ignoring it fetched me to this error message:

nvm is not compatible with the npm config "prefix" option: presently 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 pursued an earlier guide (from homebrew/nvm) and afterward that I found that I required to reinstall NodeJS. So I did:

nvm install node && nvm alias default node

and it was solved.

This may be a confrontment with your local installation of Node (in case you had it installed through another method than NVM in the past). You must 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

Afterwards you cant install nvm

On your startup script (.bashrc or .zshrc or other), alter the NVM folder to the direct path.

Ex: NVM_DIR="/bigdrive/myuser/.nvm".


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"


10 6 4
31,120 points

Related questions

0 votes
1 answer 863 views
Problem : I made the big mistake of trying remove all sudo dependencies. I simply downloaded npm as a package from the preferred site and did a manual global install. But I had to always run with the sudo. That's why I tried to uninstall and tried to run it with homebrew. ... once built. Run `brew link` on these: Now I am completely stuck and don't know how to solve it. Does anybody have any clue?
asked Nov 25, 2019 alecxe 7.5k points
0 votes
1 answer 890 views
Problem : I am new to npm and now I am facing strange looking below error “Error: EACCES: permission denied, access '/usr/local/lib/node_modules'” Detailed error as below: npm ERR! path /usr/local/lib/node_modules npm ERR! code EACCES npm ERR! errno -13 npm ... code: 'EACCES', npm ERR! syscall: 'access', npm ERR! path: '/usr/local/lib/node_modules' } Have somebody fixed this before?
asked Feb 20, 2020 mphil 2.3k points
0 votes
1 answer 29 views
Problem: I'm trying to upgrade to the latest version of node and I get the error: Sudo: npm: command not found Need help.
asked Mar 22 ummesalma 29.2k points
0 votes
1 answer 2 views
Problem: I just installed Node.js and npm (for additional modules).How can I update Node.js and the modules which I'm using to the latest versions?Can npm do it, or do I have to remove and reinstall Node.js and npm to get the next versions?
asked 2 days ago sumaiya simi 43.9k points
0 votes
1 answer 13 views
Problem: I tried to install grunt on a mac with Yosemite. node is already installed in the newest version. If I type "node -v" in the terminal I get the line v0.12.5. thats good. But when I want to install something with npm I get only a error. I tried " ... 32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) Someone knows what's the problem or better a solution?
asked Apr 12 Atik03 26.5k points
0 votes
1 answer 21 views
Problem npm err! unexpected end of json input while parsing near.
asked Feb 24 Dan phillip 4.8k points
0 votes
1 answer 49 views
Problem: I am a beginner to node.js, cordova and npm.When I try below command: $ npm install -g cordova@latest I always face below error: “Npm WARN deprecated node-uuid@1.4.8: Use uuid module instead.” Below are my system details: mac Os Sierra 10.12 ... each and every suggestion and also tried to install or uninstall the hundred times. I want to know is it a npm or cordova problem?
asked Aug 29, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 29 views
Problem : the engine "node" is incompatible with this module.
asked Feb 20 Sabbir Hossain 14.6k points
0 votes
1 answer 238 views
Problem : I am facing issues while building an app as node-sass keeps giving the following error : node sass could not find a binding for your current environment: os x 64-bit with node.js 8.x
asked Nov 15, 2019 peterlaw 6.9k points
0 votes
1 answer 31 views
Problem: I was able to install Angular. Anytime I tried to run ng, I would get: the term 'ng' is not recognized as the name of a cmdlet
asked Mar 20 ummesalma 29.2k points