nvm: oh-my-zsh: NVM is not compatible with the npm config "prefix" option
Very annoying issue; every time I want to use node or NPM, I get this error and need to run a command to solve it.
nvm is not compatible with the npm config "prefix" option: currently set to "/Users/fabian/.nvm/versions/node/v0.12.7"
Run `nvm use --delete-prefix v0.12.7` to unset it.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 141
- Comments: 335 (127 by maintainers)
Commits related to this issue
- Add delete-prefix nvm command to work around probable El Capitan bug https://github.com/creationix/nvm/issues/855 — committed to kpdecker/six-speed by kpdecker 9 years ago
- took a look at https://github.com/creationix/nvm/issues/855 problem was NVM_DIR was using HOME, no need to silence nvm — committed to yasinuslu/dotfiles by yasinuslu 8 years ago
- バグ修正 https://github.com/creationix/nvm/issues/855 NVM_DIRとしてシンボリックリンクの実態を指すようにしたら解消 — committed to suzuki-shunsuke/zsh.conf.archived by suzuki-shunsuke 8 years ago
- Work around long-standing annoying nvm bug It only shows up on one machine, where I have /home symlinked to a different mount point. creationix/nvm#855 creationix/nvm#1087 creationix/nvm#1224 creati... — committed to drewr/dotfiles by drewr 7 years ago
- Work around long-standing annoying nvm bug It only shows up on one machine, where I have /home symlinked to a different mount point. creationix/nvm#855 creationix/nvm#1087 creationix/nvm#1224 creati... — committed to drewr/dotfiles by drewr 7 years ago
- Work around long-standing annoying nvm bug It only shows up on one machine, where I have /home symlinked to a different mount point. creationix/nvm#855 creationix/nvm#1087 creationix/nvm#1224 creati... — committed to drewr/dotfiles by drewr 7 years ago
Try config the $NVM_DIR reference again.
For example nvm use v7.10.0, and have the error: Run
npm config delete prefix
ornvm use --delete-prefix v7.10.0 --silent
to unset it.You need overwrite nvm prefix,
npm config set prefix $NVM_DIR/versions/node/v7.10.0
for future wanderers:
i had to
rm /usr/local/bin/npm
so that the one from within nvm would be used and not something i installed ages ago globallyThe Fix
rm $(which npm)
if and only if it was installed by a non-nvm node and is taking precedence over nvm’s node.You can check this by doing the following:
If it points to something outside of $NVM_DIR it may be causing problems.
The explanation
I ran into this today ONLY when starting tmux. I am using oh-my-zsh on a mac however I think the following may benefit anyone.
First, I uninstalled
node
from brewbrew uninstall node
Then I debugged a ton and found that the npm being used was a leftover from my brew node installation. npm was located at/usr/local/bin/npm
but symlinked to /usr/local/lib/node_modules. Because of this, the default prefix was takining over and set to /usr/local.So I performed the following to ensure brew’s node was gone:
No more errors YAY!
In hindsight, I believe all I really needed to do was either rm the
npm
symlink in /usr/local/bin and perhaps thenpm
install source at /usr/local/lib/node_modules/bin/npm (not sure of this path).@rudeworks
nvm
is utterly unsupported on homebrew - pleasebrew uninstall
that, and install using the proper curl command in the readme, and see if you’re still having issues?I’ve just had this problem, none of the “worked for me” solutions did work for me, but I managed another way… (apologies if someone has already suggested this, I only quickly scanned this huge thread)
Run
nvm unload
thenwhich npm
. This pointed me to a copy of npm in/usr/local/bin
sym-linked to/usr/local/lib/node_modules/...
I ran
rm -rf /usr/local/lib/node_modules /usr/local/bin/npm
and the issue went awayFor what it’s worth, I had to solve this by removing a few files and directories …
I believe, but don’t have any verifiable evidence of this, that these may have gotten installed by
brew
when I installedyarn
and then had to usebrew
to force uninstallnode
.change “export NVM_DIR=~/.nvm” to absolute path “export NVM_DIR=/Users/myname/.nvm” in .zshrc file worked for me.
FWIW, I am on MacOS (High Sierra 10.13.3) and I only get this error when using the integrated terminal of VS Code (Version 1.21.1). No error on iTerm. No error on Terminal.
The Problem:
The default setting of VS Code:
"terminal.integrated.shellArgs.osx": ["-l"]
My Fix: (Note: This is just a quick band-aid fix)
"terminal.integrated.shellArgs.osx": []
bash-[versionNumber]$
.bashrc
or.bash_profile
:export PS1='$(hostname -s):${PWD##*/} $(whoami)\$ '
I had the prefix error in node 4.2.x when using a symlinked dotfiles directory (I use dotbot). Since the .nvm directory was actually sym-linked to the nvm submodule location in my dotfiles path, the real path didn’t match the
NVM_DIR
. I was able to solve it by using the followingNVM_DIR
definition in my bashrc:This way the NVM_DIR is set to the actual path wherever my dotfiles working directory is, which may be different on my various systems, although it is always linked to ~/.nvm for convenience.
I’m also getting this issue on Yosemite:
Once I run
nvm use --delete-prefix v4.1.1 --silent
it starts working normally, but I have to do it every time I open a new session.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 commandsudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
(thanks Dominic Tancredi)just
nvm use node
I met the prefix issue and solved. Because my $HOME is symbolic link, so the prefix is out of expected,
nvm_tree_contains_path "$NVM_DIR" "$NVM_NPM_PREFIX"
check failed in nvm.sh useit is solved
Just add a line before
export NVM_DIR="$HOME/.nvm"
, like this:It works for me, but don’t know why.
This code fixed for me.
In my .zshrc
I work on Debian Stretch with Bash, I solved this issue by modifying the ~/.bashrc config like this: Delete ~/.nvm and ~/.npm folders (not sure it is needed maybe just change the ~/.bashrc first): Install nvm according to the github page.
Then in ~.bashrc put (fix): 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” # This loads nvm
fix: I replaced: export NVM_DIR=“$HOME/.nvm” with: export NVM_DIR=“${HOME}.nvm” # the extra forward slash was the issue for me
then finish your installation like this: nvm install node nvm use node nvm alias default node
To know if you have the same issue as I had: in Bash do: echo $NVM_DIR # after nvm install and ~/.bashrc edited You have the same issue if you have similar output: /home/marc//.nvm/ # beware double forward slash
Using
npm config delete prefix
before loading nvm doesn’t change the output ofnpm config get prefix
. How can I ensure the prefix is deleted before loading nvm?It’s worth noting that the default “user settings” of vscode include the
-l
flag (which makes it a login shell) interminal.integrated.shellArgs.osx
.I tried setting it explicitly, but no dice:
Any other ideas? This only happens in vscode for me.
Issue solved
Upgrading nvm to v0.34.0 has fixed the issue for me. 🎉
40 thumbs, hundreds of comments, switching Node versions is still misery.
Let me be clear, I’m not blaming nvm or their maintainers. Just pointing out that no one has really nailed this down. I feel like it would be nice if the Node org came up with an official cross-platform solution.
After trying all of the above, the only thing that seemed to work for me was removing
/usr/local/bin/node
, which I have no idea how it got there 😀 Must have been from some previous installation years ago.I solve it use this in .bash_profile
you must ensure the nvm.sh excute after you define the
export NVM_DIR="${HOME}/.nvm"
chinese
我在.bash_profile文件中嵌入了如下环境配置
出现这个问题的原因是因为 执行的脚本里面要使用声明的环境变量 NVM_DIR
brew uninstall --ignore-dependencies node
solved it for me as I had an old version of node lying around.@zhouytforever run
nvm alias default node
and you should be all set. If not, please file a new issue instead of adding onto this one 😃Just in case it might help anyone. I was having this error show up every time I log in to my server and after doing
I realized I have an extra forward slash. I edited my
.bashrc
which hadexport NVM_DIR="/home/user//.nvm"
and removed this extra/
I don’t see the warning anymore.
😀,I solve this problem by removing below code in my .zshrc
I don’t realize these existed in my .zshrc while I add below to my .bash_profile after install nvm
obviously, the code in .zshrc rewrite the NVM_DIR, cause my $HOME is “/Users/huibean/” not “/Users/Huibean/”
Lots of people above have provided solutions to this including reinstall node, uninstall brew node, reinstall nvm etc.
But really the only essential step you need to do is to remove the wrong npm reference applied before your nvm script path settings.
Most of the time this is
/usr/loca/bin/npm
Which means you just need to do
rm /usr/loca/bin/npm
and restart your terminal.If this doesn’t solve the problem, you can run
which npm
before your nvm path setting script to find out what is it, and just remove it.curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
解决问题.
Thanks! @ljharb I used the curl command (
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
) to install version v0.34 but now that I’m runningnvm --version
, I’m still seeing v0.33.11@ljharb ok, no problem. by the way, you said “can you file a new issue” in fact, you would like to say “can you open a new issue”
I met this issue as well, and resolved it by added the following lines to
~/.zshrc
file.I solved this by removing the
prefix=
line from my.npmrc
file.NOTE: I’m not using oh-my-zsh, but I can’t be the only Terminal user who ended up here. 🤠
@bryansray Thanks! Yeah,
brew install yarn
also installs Node.js. To fix the problem I had to:brew uninstall node
Certainly using brew to install node has broken things for a lot of people; thanks for that suggestion.
This error occurred when my
$HOME
was a symlink. Replacingwith
worked for me.
Upgrading to the latest version of
nvm
fixed the issue for me (0.35.3). As a precaution, I removed the~/.nvm
directory and installed fresh versions of Node.js using the updatednvm
.See https://github.com/nvm-sh/nvm for instructions.
Hi, Like some of the others, I too was only experiencing this issue in vscode. I am on version
0.33.11
. Afteer some tinkering around, I unchecked the Terminal > Integrated > Inherit Env option. Here is the corresponding setting in json:"terminal.integrated.inheritEnv": false
This seemed to have fixed the issue for me.upgrading had no effect for me. fwiw, my system was set via a template provided by my org. by default it put all the homes under
/local
so/home/bill
was a symlink to/local/home/bill
. this caused oh-my-zsh plugins and others to have an issue. (Perhaps it detected/home/bill/.nvm !== /local/home/bill/.nvm
and assumed it was a prefix…??)When I explicitly set
export NVM_DIR=/local/home/bill/.nvm
then everything worked fine, including the official and zsh-nvm pluginsHTH
https://github.com/creationix/nvm/issues/855#issuecomment-147127139
@ljharb This fixed it for me! Must be something to do with
~/
in zsh? 🤔Hi everyone,
I had the same issue, but after I have read /usr/local/opt/nvm/README.md and made change in ~/.zshrs to
The message has been disapeared and everything looks working.
Have a nice day!
I am on a mac v10.13.2, i am using oh-my-zsh, i’ve install nvm using Homebrew.
For me this solution work very well: 1 - brew uninstall nvm 2 - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash it work on Terminal as well as iTerm, but the problem persist on VScode.
I was able to resolve this issue by exporting
NPM_AUTH_TOKEN
before the NVM setup in my.zshrc
.I had this issue as well. Figured out that I had installed
node
via homebrew prior to installingnvm
.So the solution was: uninstall homebrew’s node, and the issue is fixed.
@abr4xas if you change that to
export NVM_DIR="$HOME/.nvm"
your problems will go away.Hi guys, this is not a solution but just an quick work-around idea:
at least you will be able to use node with every new terminal session 😃
Had this issue from operator error and corrected it.
This works for me ⬇️
⬆️
more can be said,this situation occur in vscode’s terminal
Same here.
@dan-j’s solution solved my problem
Just a little update here as it may help some: The wrong npm (
/usr/local/lib/node_modules/npm/bin/npm
) was symlinked to/usr/local/bin/npm
I removed the symlink, so now my npm is the nvm one ($NVM_DIR/versions/node/<version>/bin/npm
) And no prefix anymore 😃What if you try
export NVM_DIR="/Users/isaac/.nvm"
?I’ve added
$HOME
info tonvm debug
in c957989fa96ca28994e130cc3682eee87eb40a9f to hopefully try to catch this sooner next time 😃@ljharb I have tried nvm with pure
zsh
, withoh-my-zsh
and withzgen
all of them have this bugHello, On my side, all of these solutions did not solve my problem.
But I finally find it, my $HOME value was /Users/alexandre while the real path was /Users/Alexandre. So I first hardcoded the NVM_DIR var with the matching case, and as it was ok I finally renamed by home folder all in lower case to avoid other similar problems.
Hope it helps too…
uninstall node version(broken), and reinstall node version. here is a example:
nvm uninstall v4.7.3 && nvm install v4.7.3
No, “can you file” is correct. “file” and “open” are a synonym when applied to issues.
thanks @ljharb the install instruction clearly mentions that brew install is not supported. Do not get this with a curl installation as mentioned.
@ljharb this issue is now gone on Bash for Windows using Insider Preview build 15051
I had a case issue on (10.12|zsh) although $HOME returned /Users/name, when I checked the /Users it was still in /Users/Name - renaming the folder to lowercase fixed the issue.
guys I had the same problem. and I managed to fix it by just adding
export NPM_TOKEN=""
before nvm loading in oh-my-zsh and it fixed.Note when i tried
npm config get prefix
it failed too as it is used in the nvm. As i dig into npm code i found that they tries to aggregate the env variables global variables into one variable atv6.9.4/lib/node_modules/npm/lib/config/core.js
this might be sillyI think i might face issues when i try to npm login.
For me, it works to re-install node with nvm.
Assume that the version is 6.9.1,
With above command, the warning message is vanished!
Been having this issue for weeks now, for me the fix was:
where
on OSX 10.11 ans zsh (omzsh)
is there anything in
~/.npmrc
that references that PEM file?@davidpronk your problem is that you have npm installed in
~/.node
, and you have that set as your prefix - check~/.npmrc
, and the PREFIX or NPM_CONFIG_PREFIX environment variables - these must be unset fornvm
to work.@bsorem-sugarcrm please do not ever install
nvm
with homebrew. It’s completely unsupported. Install using the curl command in the readme, please.Sorry, I am using oh-my-zsh yes. And just to confirm, the first bad commit is 1458de7
One thing I am doing though, is symlinking ~/.nvm to ~/Development/nvm (i.e. ~/.nvm is the symlink). So
npm config get prefix
always gives me a result that is outside of ~/.nvm.Getting rid of the symlink, and moving the nvm dir to a single location and sourcing it from there only, also gets rid of the error.
If you try to set the “prefix” that will break
nvm
.As a temporary workaround, you can do
nvm use --delete-prefix v0.12.7
, but this is a bug specifically withomz
. I’ll have to figure out which option to unset when doing the comparison.This issue was resolved in v0.37.0 with #2317
@Xananax would you mind filing that as a new issue, with the full issue template filled out?
Btw, just noticed that Fedora Silverblue also uses symlinks in home paths:
UPDATE: However, it doesn’t seem to be triggering the
prefix
error message (like e.g. on FreeBSD), as Fedora seems to set$HOME
to the physical path (so without a symlink in it).how to fix:
~/.zprofile
source ~/.zprofile
zsh
.if that doesn’t work
source ~/.zprofile
again.Let’s file a separate issue to discuss that then; that sounds more complicated.
@ljharb thanks, that worked!
@donaral try removing your system node
@ceccode i suspect that’s a different problem, related to the files tmux is sourcing. Can you file a separate issue?
I am on a mac v10.13.16, i am using oh-my-zsh. It work on Terminal as well as iTerm, but the problem persist with Tmux
That issue doesn’t apply when using nvm, so no prefix is needed. Either way, regardless of npm’s advice, setting the prefix isn’t a good idea.
@ljharb I set prefix to avoid permission issue related to this post
I am using dotfiles , so yes. But I set the NVM_DIR to the actual path.
That’s the root problem I guess. I will try reinstalling without dotfiles symlink.
Thanks
@reallistic save my day!
The difference is I installed yarn by brew, so I need to add one more option
--ignore-dependencies
to successfully remove node from brew.Yarn could not get any
node
for now,nvm use [node-version]
will solve this problem.Everything work as expected.
My .zshrc looked liked this:
and i got the same problem. It got fixed when i called the
init-nvm.sh
earlier. Not at the end but near at the beginning.@ljharb thank you a lot, you save my day!
@ljharb thanks. Looked it up on the MS side and for Bash for Windows this is a known issue https://github.com/Microsoft/BashOnWindows/issues/1683. I’m not seeing it on macOS.
@luixaviles in your case there’s no issue; it’s literally working exactly as designed 😃 you had a “prefix” setting in
~/.npmrc
, and the--delete-prefix
command removed it. 🎉uninstalling 6.9.1 and reinstalling doesnt work for me. i am on ubuntu 16.04.01.
I am using oh-my-zsh, It seems it doesnt want to delete the prefix… hmm.
Here’s the Google Translate version of @myoneray’s previous comment in English:
@ljharb: Filed https://github.com/creationix/nvm/issues/1245 for my symptoms.
@ljharb - No. My cenario was this:
1 - installed osx and created ‘alexandre’ user; 2 - installed nvm; 3 - changed ‘alexandre’ home and settings to ‘Alexandre’; 4 - the annoing bug started and
--delete-prefix
only fixes temporary (session); 5 - changedNVM_DIR
from ‘alexandre’ to ‘Alexandre’ on .zshrc; 6 - run one time with--delete-prefix
and this totally fixed the bug for me;@Daniel-ltw See my comment above, https://github.com/creationix/nvm/issues/855#issuecomment-186935754, and my corresponding mini-containers/base comment, https://github.com/mini-containers/base/issues/5#issuecomment-186934231.
In short, on Alpine, the musl standard C library is missing some symbols, causing the dynamic linker to fail, resulting in the “No such file or directory” report for a binary that very clearly exists. So it seems nvm currently isn’t compatible with Alpine. (Unless someone with deeper and knowledge and experience than me can report otherwise.)
ugh - that fixed it. that was embarassing 😞 Thanks a lot for looking into this.
I’m wondering if perhaps it’s related to your home dir being
Ying
andNVM_DIR
beingying
? Do you have a case-insensitive filesystem?I have the same issue,
npm config get prefix
=>/data1/home/oswap/.nvm/versions/node/v5.6.0when i use following line command:
npm config set prefix /home/oswap/.nvm/versions/node/v5.6.0
resolved!
I ran into the same issue just because I had
NVM_DIR="/opt/nvm/"
instead ofNVM_DIR="/opt/nvm"
into my .zshrc .same here, on OSX 10.10.4 (Yosemite)
If I can help in anyway, tell me
@ljharb here is the output for
nvm debug
:Thanks! so, clearly you don’t have an npm prefix set.
Are you by chance using
oh-my-zsh
? That tends to set tons ofopts
thatnvm
has to manually account for.Thanks for the report! What does
nvm deactivate ; nvm debug ; echo $PREFIX ; echo $NPM_CONFIG_PREFIX
print out?