nvm icon indicating copy to clipboard operation
nvm copied to clipboard

NVM Use Default does not persist - macos with zsh

Open JoshuaVSherman opened this issue 3 years ago • 20 comments

Operating system and version:

macOS Big Sur

nvm debug output:

nvm --version: v0.37.0
$TERM_PROGRAM: iTerm.app
$SHELL: /bin/zsh
$SHLVL: 1
whoami: 'joshuasherman'
${HOME}: /Users/joshuasherman
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: /usr/local/opt/[email protected]/bin:/usr/local/opt/[email protected]/bin:/usr/local/opt/[email protected]/bin:/usr/local/opt/[email protected]/bin:/usr/local/opt/rabbitmq/sbin:${NVM_DIR}/versions/node/v14.11.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/usr/local/opt/rabbitmq/sbin:/usr/local/opt/rabbitmq/sbin:${HOME}/.local/bin:${HOME}/.local/bin
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.8 (x86_64-apple-darwin20.0)'
uname -a: 'Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64'
checksum binary: 'shasum'
OS version: macOS 11.6 20G165
curl: /usr/bin/curl, curl 7.64.1 (x86_64-apple-darwin20.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.41.0
wget: not found
sed: /usr/bin/sed
cut: /usr/bin/cut
basename: /usr/bin/basename
rm: /bin/rm
mkdir: /bin/mkdir
xargs: /usr/bin/xargs
git: /usr/bin/git, git version 2.30.1 (Apple Git-130)
ls: grep:: No such file or directory
grep: grep: aliased to grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox} (grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}), grep (BSD grep) 2.5.1-FreeBSD
awk: /usr/bin/awk, awk version 20200816
nvm current: v14.11.0
which node: ${NVM_DIR}/versions/node/v14.11.0/bin/node
which iojs: iojs not found
which npm: ${NVM_DIR}/versions/node/v14.11.0/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v14.11.0
npm root -g: ${NVM_DIR}/versions/node/v14.11.0/lib/node_modules

nvm ls output:

       v10.22.1
       v10.23.0
       v12.19.1
       v12.20.0
       v12.20.1
       v12.21.0
       v12.22.0
       v12.22.1
       v12.22.4
       v12.22.6
       v14.10.1
->     v14.11.0
       v14.12.0
       v14.13.0
       v14.13.1
       v14.14.0
       v14.15.0
       v14.15.1
       v14.18.0
       v14.18.1
       v14.18.2
        v15.0.0
        v15.0.1
        v15.2.1
        v16.8.0
       v16.10.0
       v16.13.0
        v17.0.0
default -> 14.18.2 (-> v14.18.2)
node -> stable (-> v17.0.0) (default)
stable -> 17.0 (-> v17.0.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/gallium (-> v16.13.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.7 (-> N/A)
lts/fermium -> v14.18.2
lts/gallium -> v16.13.0

How did you install nvm?

curl

What steps did you perform?

nvm alias default 14.18.2 nvm use default then open a new terminal tab node --version and it is still 14.11.0

What happened?

does not persist default

What did you expect to happen?

14.18.2 should be the default version

Is there anything in any of your profile files that modifies the PATH?

I have this in my .zshrc

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 bash_completion

JoshuaVSherman avatar Dec 01 '21 13:12 JoshuaVSherman

You're on an outdated nvm; what happens if you update to the latest?

ljharb avatar Dec 01 '21 16:12 ljharb

upgrading to 0.39.0 did not fix

JoshuaVSherman avatar Dec 01 '21 17:12 JoshuaVSherman

granted this is not really a big deal, I just have to remember to nvm use default whenever I start, but still, it would be nice if it persisted, thanks

JoshuaVSherman avatar Dec 01 '21 17:12 JoshuaVSherman

Thanks for checking.

Is there anything in any of your profile files that hardcodes the PATH to have 14.11 in it?

ljharb avatar Dec 01 '21 17:12 ljharb

The fact that nvm current says v14.11.0, and nvm use 14 sets it to v14.18.2, means nvm is working, so the issue is somewhere else.

Do you have an .nvmrc file in the current directory that sets v14.11.0?

ljharb avatar Dec 01 '21 17:12 ljharb

No

On Wed, Dec 1, 2021, 12:22 PM Jordan Harband @.***> wrote:

The fact that nvm current says v14.11.0, and nvm use 14 sets it to v14.18.2, means nvm is working, so the issue is somewhere else.

Do you have an .nvmrc file in the current directory that sets v14.11.0?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nvm-sh/nvm/issues/2669#issuecomment-983860927, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADFY3WHMHHBWHCYBUNK4UC3UOZKUNANCNFSM5JEQF2YA .

JoshuaVSherman avatar Dec 02 '21 00:12 JoshuaVSherman

If you run nvm_find_nvmrc, is anything printed out?

If you run nvm use system && nvm_auto && nvm current what is printed out?

ljharb avatar Dec 02 '21 07:12 ljharb

Hey guys, I'll join the conversation as I started experiencing something similar after upgrading to Monterey on mac. In my case I only have one version installed and when I boot up, node and all related commands are not found and nvm ls gives: Screenshot 2021-12-02 at 09 54 45

Running nvm_find_nvmrc logs nothing Running nvm use system && nvm_auto && nvm current outputs: System version of node not found.

Basically I just added nvm use default to .zshrc as a temporary fix

UPDATE:

Ok, I seemed to resolve the issue by re-installing xcode-select and nvm 👍

snigo avatar Dec 02 '21 09:12 snigo

@snigo i suspect merely rerunning xcode-select --install would have fixed it; glad you're all set.

ljharb avatar Dec 02 '21 18:12 ljharb

I'm having this problem too. Reinstalling xcode-select and nvm didn't fix it.

% nvm_find_nvmrc
% nvm use system && nvm_auto && nvm current
System version of node not found.
% nvm ls
       v16.15.1
        v18.7.0
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v18.7.0) (default)
stable -> 18.7 (-> v18.7.0) (default)
lts/* -> lts/gallium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.20.0 (-> N/A)
lts/gallium -> v16.17.0 (-> N/A)

NodeGuy avatar Oct 07 '22 23:10 NodeGuy

@NodeGuy you don't have a default version set. "(default)" there means it's a default/built-in alias. Try nvm alias default node.

ljharb avatar Oct 07 '22 23:10 ljharb

Thank you, that fixed it! I wasn't aware of the "default" distinction, only that NVM had been working for a long time and then stopped.

NodeGuy avatar Oct 08 '22 01:10 NodeGuy

For what it’s worth, I’m running into a similar issue: nvm’s default is 18.11.0, but a new terminal is using 19.0.0. I tried xcode-select --install and also tried reinstalling nvm. Same result:

$ node --version
v19.0.0
$ nvm --version
0.39.2
$ nvm list
       v18.11.0
->      v19.0.0
default -> 18.11.0 (-> v18.11.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v19.0.0) (default)
stable -> 19.0 (-> v19.0.0) (default)
lts/* -> lts/gallium (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.20.1 (-> N/A)
lts/gallium -> v16.18.0 (-> N/A)
$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

That said, I install nvm via Homebrew, so maybe that’s the issue 🤷

I’m on macOS 12.6, running the default zsh shell.

leafac avatar Oct 24 '22 13:10 leafac

@leafac do you have an .nvmrc file anywhere that’s set to “stable” or “node”?

ljharb avatar Oct 24 '22 15:10 ljharb

@ljharb First, thanks for the response. (And for all your work on open-source software 😁)

I’ve never created .nvmrc files myself. I also checked the following locations:

  • Project folder and parents.
  • $NVM_DIR.

And I couldn’t find any .nvmrc files lurking there either.

Do you think I should check anywhere else?

leafac avatar Oct 24 '22 15:10 leafac

It could be in any folder up to /, but the only other likely place is $HOME.

If not that, then could you provide your nvm debug output?

ljharb avatar Oct 24 '22 15:10 ljharb

@ljharb: It could be in any folder up to /, but the only other likely place is $HOME.

Yes, I checked them. That’s what I meant by “Project folder and parents.” The project folder happens to be in my $HOME, so that’s covered.

If not that, then could you provide your nvm debug output?

$ nvm debug
nvm --version: v0.39.2
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/zsh
$SHLVL: 1
whoami: 'leafac'
${HOME}: /Users/leafac
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: /opt/homebrew/opt/python/libexec/bin:${NVM_DIR}/versions/node/v18.11.0/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.8.1 (x86_64-apple-darwin21.0)'
uname -a: 'Darwin 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101 arm64'
checksum binary: 'shasum'
OS version: macOS 12.6 21G115
curl: /usr/bin/curl, curl 7.79.1 (x86_64-apple-darwin21.0) libcurl/7.79.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.45.1
wget: /opt/homebrew/bin/wget, GNU Wget 1.21.3 built on darwin21.3.0.
sed: /usr/bin/sed
cut: /usr/bin/cut
basename: /usr/bin/basename
rm: /bin/rm
mkdir: /bin/mkdir
xargs: /usr/bin/xargs
git: /opt/homebrew/bin/git, git version 2.36.1
grep: /usr/bin/grep, grep (BSD grep, GNU compatible) 2.6.0-FreeBSD
awk: /usr/bin/awk, awk version 20200816
nvm current: v18.11.0
which node: ${NVM_DIR}/versions/node/v18.11.0/bin/node
which iojs: iojs not found
which npm: ${NVM_DIR}/versions/node/v18.11.0/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v18.11.0
npm root -g: ${NVM_DIR}/versions/node/v18.11.0/lib/node_modules

(And I’ll say this again just in case: I install nvm via Homebrew. If think that this may be the issue, I’m happy to test the official nvm installation method…)

leafac avatar Oct 24 '22 16:10 leafac

That looks fine, and assuming that nvm use node or nvm use 19 work as expected, then that's not the issue either. There's nothing in your zsh profile files (.zprofile or .zshrc, afaik) that runs any nvm commands?

I doubt homebrew would affect this, but it's affected surprising things before, so it might be worth checking.

ljharb avatar Oct 24 '22 17:10 ljharb

I am facing something similar as well. My nvm use <version> will say that I am now using the version of node I specified but then when I node -v it's not using the node version I wanted.

➜  ~ nvm -v   
0.38.0
➜  ~ nvm use   
No .nvmrc file found
Please see `nvm --help` or https://github.com/nvm-sh/nvm#nvmrc for more information.
➜  ~ nvm use 16
Now using node v16.4.2 (npm v7.18.1)
➜  ~ node -v   
v14.17.1
➜  ~ nvm list  
         v4.9.1
        v8.17.0
       v10.24.1
        v14.5.0
       v14.17.6
       v15.14.0
        v16.4.2
        v17.3.1
->       system
default -> 16 (-> v16.4.2)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v17.3.1) (default)
stable -> 17.3 (-> v17.3.1) (default)
lts/* -> lts/gallium (-> N/A)
lts/argon -> v4.9.1
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0
lts/dubnium -> v10.24.1
lts/erbium -> v12.22.10 (-> N/A)
lts/fermium -> v14.19.0 (-> N/A)
lts/gallium -> v16.14.0 (-> N/A)

I have tried using nvm alias default <version> still have no luck. Every time I try switching node versions it will always be whatever system is set to.

The part I don't understand is how my which node and npm root -g is pointing to something else other than my NVM_DIR

➜  ~ nvm debug
nvm --version: v0.38.0
$TERM_PROGRAM: Apple_Terminal
$SHELL: /bin/zsh
$SHLVL: 1
whoami: 'rembrandt.reyes'
${HOME}: /Users/rembrandt.reyes
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: ${HOME}/Library/Python/3.8/bin:${HOME}/.rvm/gems/ruby-2.7.2/bin:${HOME}/.rvm/gems/ruby-2.7.2@global/bin:${HOME}/.rvm/rubies/ruby-2.7.2/bin:/usr/local/opt/[email protected]/bin:/usr/local/opt/[email protected]/bin:/usr/local/opt/[email protected]/bin:${HOME}/.yarn/bin:${HOME}/.config/yarn/global/node_modules/.bin:${NVM_DIR}/versions/node/v16.4.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:${HOME}/.rvm/bin
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.8 (x86_64-apple-darwin20.0)'
uname -a: 'Darwin 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 29 04:31:06 PDT 2022; root:xnu-7195.141.39~2/RELEASE_X86_64 x86_64'
checksum binary: 'sha256sum'
OS version: macOS 11.7 20G817
curl: /usr/bin/curl, curl 7.64.1 (x86_64-apple-darwin20.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.41.0
wget: /usr/local/bin/wget, GNU Wget 1.21.3 built on darwin20.6.0.
sed: /usr/bin/sed
cut: /usr/bin/cut
basename: /usr/bin/basename
rm: /bin/rm
mkdir: /bin/mkdir
xargs: /usr/bin/xargs
git: /usr/local/bin/git, git version 2.33.0
ls: grep:: No such file or directory
grep: grep: aliased to grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox} (grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}), grep (BSD grep) 2.5.1-FreeBSD
awk: /usr/bin/awk, awk version 20200816
nvm current: system
which node: ${HOME}/Library/Python/3.8/bin/node
which iojs: iojs not found
which npm: ${NVM_DIR}/versions/node/v16.4.2/bin/npm
npm config get prefix: ${HOME}/Library/Python/3.8
npm root -g: ${HOME}/Library/Python/3.8/lib/node_modules

rembrandtreyes avatar Oct 28 '22 20:10 rembrandtreyes

@rembrandtreyes for you, it's because you have a "node" binary somehow installed under a Python 3.8 dir, and that directory appears sooner in your PATH than nvm's directories.

ljharb avatar Oct 28 '22 21:10 ljharb

same bug here.

so frustrating.

I did use nvm alias default 18.13.0, but still node -v shows it's node14.

so, yeah, maybe i will have to add nvm use default in zshrc

medmin avatar Mar 10 '23 22:03 medmin

@medmin same thing - make sure that sourcing nvm happens after any other PATH changes, so that nvm takes precedence over everything else.

ljharb avatar Mar 10 '23 22:03 ljharb

yes i can confirm that reinstalling nvm solves the issue on mac os 13 ventura and zsh

sombriks avatar May 02 '23 16:05 sombriks

I'm going to close this since it doesn't seem actionable for nvm, but please file a new issue with a filled-out template if you're still having problems.

ljharb avatar May 02 '23 16:05 ljharb

had an exactly the same issue, re-installed nvm using curl, solved the issue. Thanks everyone.

sichallez avatar Aug 31 '23 05:08 sichallez