nvm is not compatible with the npm config "prefix" option:
Asked Answered
D

23

306

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?

Deoxyribose answered 11/1, 2016 at 9:56 Comment(11)
I use npm config delete prefix to get around this, no problem so farLashkar
@DanWhite If I delete prefix, I lose diverting my global installs into dedicated directory.Deoxyribose
(nvm maintainer here) That's the point. With nvm, it, not you, manages your global installs. Separately, global installs should never be shared across node versions.Malfeasance
@Malfeasance Thank you for taking time to comment! It would be great if 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 the nvm simply override that setting as long as it is active? So the nvm would use its own settings, and I can keep my previous working state when I exit nvm to return to my regular node version.Deoxyribose
@DmitriZaitsev because it's an npm setting, and nvm can't control where npm looks for config. There's no way I know of for nvm to override npm's setting in a per-shell way, and I didn't want to automatically delete the prefix (thus changing your settings destructively) without the user's explicit consent.Malfeasance
@Malfeasance I was assuming the nvm would replace the current node and the npm for the chosen version with nvm use <version>. Then the new npm would have its own setting, a sort of "override" but better ;). That way, the new npm would not even "know" about the old prefix, so the problem shouldn't even exist. Or does the nvm only replace the node but keeps the old npm (which would be confusing imo)? I was also assuming the switch to selected node version was not per-shell, was it?Deoxyribose
Each copy of node comes with its own npm, which determines its own settings.Malfeasance
Indeed, each selected node version with nvm is per-shell - that's by design.Malfeasance
I had this error message after have set myself npm to install avoiding sudo myself, following this #18212675. I wonder then if that type of "workaround" is recommended and if fixing the local prefix as the accepted answer here will make me able to both install local package without sudo and have the prefix "fiexed". Also another concern is about the fact that the suggested solution i used create a ".node" folder that could interferwith "node" in unix systemKraemer
@Malfeasance please answer this simple binary question: does the discussed limitation effectively beat us back to having to install global packages with sudo, OR does it SOLVE this problem in its own way (i.e. installing global packages with nvm does NOT require sudo)?Crabbed
@SzczepanHołyszewski it obviates the need to use sudo, because the place global npm modules are installed (npm 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
F
535

Delete and Reset the prefix

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

Fincher answered 18/12, 2017 at 2:20 Comment(15)
This worked like a charm! Just had to grab my node version.Blackandblue
I seemed to have a symbolic link /usr/local/bin/node that would cause integrated terminal in vscode to see a node version it shouldn't have seen. Following the steps above and then deleting the symbolic link appears to have fixed the issue. My node and npm are governed by nvm nowColy
this works perfect. just do not miss to set prefix the node version, you are going to use. npm config set prefix $NVM_DIR/versions/node/<node-version-directory>Goodkin
This only works in the current window. If you open a new shell or a new window you have to do it all over again.Delorisdelorme
Personally, I just had to run the first command to delete the prefix: npm config delete prefix. I recently upgrade node from version 7 to version 10.Santos
Just deleting it should be fine. However, if set, it should be to $NVM_DIR/current.Denicedenie
I have to do these in order. 1. nvm use --delete-prefix vx.x.x --silent 2. npm config delete prefix 3. npm config set prefix $NVM_DIR/versions/node/vx.x.xGrantham
I could not run npm because I got error nvm is not compatible. So at first run I did nvm use --delete-prefix .... Then I could run npm config delete and npm config setBentinck
@Delorisdelorme I got rid of this from happening when opening a new shell by deleting a rogue $HOME/.nvmrcEuphemize
@Euphemize delete folder without an explanation does not seems to me advisableKraemer
@CarmineTambascia yes my bad! i meant i deleted a $PATH edit in a *rc file!Euphemize
npm use afterVise
What I don't understand about this solution is how manually setting the version fits with the use of nvm. If the whole point of nvm is to be able to dynamically shift between version based on context, then the need to manually set the version seems to negate that.Grimace
Not on mac though.Mauretania
after running the commands: ``` $ npm config delete prefix $ npm config set prefix $NVM_DIR/versions/node/v6.11.1 ``` calling nvm use now doesn't update node version. Any idea why that would be?Stinger
G
84

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.

Groome answered 3/3, 2016 at 13:51 Comment(12)
Fwiw I had to export NVM_DIR=/usr/local/Cellar/nvm/0.31.0 (instead of ~/.nvm)Cynosure
nvm alias default node seemed to helped me in my caseCayla
(nvm maintainer here) nvm is not supported when installed via brew. Please uninstall it and use the proper method, the curl script in the readme.Malfeasance
I used the curl script to install nvm. This answer did not work for me.Cod
@Cod Did you find a solution that did?Azral
@JakeT. it's been so long I don't remember. I upvoted Mick's answer, so maybe that worked, but if it did I don't know why I commented on this one...Cod
@Cod Thanks. I ended up doing a complete fresh install of node using nvm based on this guide: nearform.com/blog/how-to-manage-node-js-sudo-free-with-nvm And my hangup ended up being that I had previously installed using homebrew, which is no longer supported. It left a lot of remnants that took a while to clear, and then I had to rm -rf node_modules and run npm install again, since the directories already had screwy permissions issues.Azral
For the clarity of posterity, I had to do a brew remove node -f, which removes all installed versions. Do this first, then follow the guide in my link above, then remove node_modules. You should get a clean install! I think you then have to install npm as well, which I just followed the instructions from a nodejs.org article that popped up when I searched for it. npm install npm@latest -g was the command, once you install node.Azral
@Malfeasance [nvm maintainer] instruction is working for me. install using curlAnguiano
Thank you! The following worked for me: "nvm install node && nvm alias default node"Cadman
the brew --prefix syntax here was crucial for me -- trying to run the nvm.sh directly produced a prefix complaint, and wouldn't set the node version.Limnetic
I recently was playing with Apple's GPTK and that changed my .bash_profile and added this line: eval "$(/usr/local/bin/brew shellenv)" which caused the issue with nvm and prefix. The trick to delete prefix via command was okay but it wasn't permanent obviously. I simply deleted that line from .bash_profile and now everything is back to nornal.Undeceive
H
40

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

Habiliment answered 23/1, 2018 at 7:39 Comment(7)
Would you like to augment your code-only answer with some explanation? The comments are not enough, because your commandlines are more intricate than explained by them. Elaborate why the details of your answer solve the problem. Contrast your answer against the years older answers. What makes your answer an added value to this question?Cassandracassandre
For me, the empty first code line (which you recently added) needs its own explanation...Cassandracassandre
After five months on StackOverflow, consider taking the very enlightening guided help tour.Cassandracassandre
While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations!Larondalarosa
"After you cant install nvm" So, if my goal is to use nvm, I shouldn't do this?Azral
Removing the node links is what did it for me (stray npm symlink was hanging around).Shrapnel
Some explanation would definitely help. nvm works fine for me, after following the above steps and yes, it works in new terminals (even those within webstorm & vscode).Centrality
P
37

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"
Palpate answered 25/10, 2019 at 13:57 Comment(5)
Thanks! Your answer should have more visibilityMillion
Nope. I fried my brain to understand this crazy error. I didn't find any posts that helped me. I had to fight hard to solve the problem. I am happy to help you. Vote on my answer to be more visible.Cancellate
my echod $NVM_DIR was "/Users/vijayshanker/.nvm" should i put "export NVM_DIR="/Users/vijayshanker/.nvm(and the rest)" in bashrc, tried but it still did not fixed it, been struggling for 6 hours, please help note:i don't have npm installed, i did not installed my node from npmApprover
one solution maybe to export NVM_DIR=$(readlink -f "$HOME/.nvm") in .bashrc or command line. This will remove all symlink from $HOME/.nvm and export a plain full path with only real directories.Wethington
export HOME="/big/drive/myuser" This should be more resilient. though for your situation, i would just use fstab to bind mount it. I might go that route if this causes any more issues.Thorman
T
13

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.

Tella answered 7/6, 2017 at 9:44 Comment(0)
S
10

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
Senhauser answered 13/12, 2016 at 10:22 Comment(0)
V
7

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*}

Venita answered 29/4, 2016 at 11:22 Comment(0)
B
7

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"
Bargeboard answered 25/11, 2019 at 16:21 Comment(1)
Came here to put the same comment :) In my case was because when I created the user I set the home as useradd --home /home/user/ with the trailing / I removed from the /etc/passwd file and everything start working againPlaton
R
5

There are just two commands to resolve this issue. Some users may also be getting the error as soon as they are also opening the terminal. The first thing they see is this error:

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.

So to resolve this issue, Run the following two commands. Note: Change the version number as the same they are showing in your error.

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

Note: This will also work if your terminal is using zsh.

Repertoire answered 27/2, 2022 at 7:29 Comment(0)
A
3

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

Aryanize answered 19/9, 2019 at 21:20 Comment(0)
U
2

I've tried every answer in this thread but none worked. Reinstalling nvm as documented https://github.com/nvm-sh/nvm with curl fixed my problem.

Unread answered 12/3, 2021 at 0:4 Comment(1)
wow, this saved me an epoch of time. all I did was run this and was back up and running! curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bashGeneric
P
1

I followed https://mcmap.net/q/99459/-nvm-is-not-compatible-with-the-npm-config-quot-prefix-quot-option 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.

Phototransistor answered 10/2, 2019 at 15:33 Comment(0)
S
1

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.

Sublapsarianism answered 19/4, 2019 at 16:50 Comment(0)
E
1

For those who first installed node via homebrew and then added nvm to a system.

If you see noisy message : nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local you may need to delete the node_modules and node itself, the solution was perfectly described above^^, but below is simple way.

Since brew automatically added env var to .bash_profile, each time bash loaded path points to the originally installed version.

1.Go to ./.bash_profile 2. Comment on line which points to node, like so #export PATH="/usr/local/opt/node@10/bin:$PATH"

next time bash should load node which is installed by nvm, make sure bash_profile contains nvm dir export NVM_DIR="/Users/{your_user_name}/.nvm"

Ephraimite answered 7/5, 2021 at 11:31 Comment(0)
C
1

Following sh file helped my case

# nvmish.sh
unset npm_config_prefix
source $HOME/.nvm/nvm.sh
nvm use 18
Calisaya answered 27/10, 2022 at 7:44 Comment(0)
W
0

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
Wifeless answered 3/5, 2016 at 17:3 Comment(0)
F
0

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

Fusillade answered 17/4, 2017 at 13:34 Comment(0)
U
0

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

Unfreeze answered 28/1, 2018 at 10:29 Comment(2)
What about installing nvm with npm?Deoxyribose
Installing nvm through homebrew is officially deprecated and leads to issues due to some incompatibilities. The official way is to use curl/wget, see github.com/creationix/nvm#install-script see github.com/creationix/nvm/issues/298#issuecomment-152255091 Installing through npm isn't supported AFAIK, because nvm installs npm, so if npm also installs nvm it can lead to edge cases. You can read about it on the issue I previously linked.Phototransistor
C
0

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.

Chiarra answered 3/8, 2018 at 8:50 Comment(0)
E
0

For me I removed the lines

NPM_PACKAGES="${HOME}/.npm-packages"

PATH="$NPM_PACKAGES/bin:$PATH"

From my .bashrc and was able to run npm install -g package-name without needing sudo permissions or having the error message appear in my shell window.

Enthymeme answered 27/5, 2021 at 6:57 Comment(0)
M
0

I faced the same issue, This is because of conflicting the npm of node and nodejs

so remove nodejs by below commands

sudo apt-get remove nodejs

this will remove all nodejs related Packages,

after the above command, you have to run autoremove command just like that

sudo apt autoremove

this will solve the problem,

Mcglone answered 31/8, 2021 at 12:57 Comment(0)
B
0

Here is what I did and worked for me

1- sudo su

2-root@antonio:/home/antonio# mv ~/.nvm /tmp/

3- root@antonio:/home/antonio# export NVM_DIR="/tmp/.nvm"

4- root@antonio:/home/antonio# nvm use --delete-prefix v17.4.0

5- `root@antonio:/home/antonio# node -v

enter image description here`

Bianco answered 23/1, 2022 at 23:4 Comment(0)
M
-3

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

Manvil answered 25/2, 2017 at 9:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.