• Register
0 votes
397 views

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

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.

OR

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

Solution:

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".

.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"

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 485 views
485 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 607 views
607 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 mphil 2.3k points
0 votes
1 answer 13 views
13 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 Raphael Pacheco 4.9k points
0 votes
1 answer 115 views
115 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 11 views
11 views
Problem: I am very new to cordova, phonegap, ant,sdk,jdk. I am learning to use phonegap/cordova. Everything is installed properly on my machine i.e cordova, phonegap, ant,sdk,jdk. But now suddenly it started saying that: "’Node' is not recognized as an ... insufficient knowledge I am unable to fix this issue. I am looking for cordova and phonegap experts who can help me in fixing this issue.
asked Sep 2 Raphael Pacheco 4.9k points