Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nvm current returns system instead of version number, suspect nvm use not working #2686

Closed
zigotica opened this issue Dec 15, 2021 · 29 comments
Labels
installing nvm Problems installing nvm itself non-issue / invalid This isn't relevant to nvm, or turned out to be something unrelated.

Comments

@zigotica
Copy link

problem description

nvm current returns system instead of version number (i.e. v16.13.1). I need the version number not an alias, I suspect nvm use vX.Y.Z is not working.

Operating system and version:

macOS 12.1 21C52 arm64

nvm debug output:

nvm --version: v0.39.0
$TERM_PROGRAM: tmux
$SHELL: /opt/homebrew/bin/bash
$SHLVL: 2
whoami: 'sergi'
${HOME}: /Users/sergi
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: /opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/bin:/opt/homebrew/sbin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/bin:/opt/homebrew/sbin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/bin:/opt/homebrew/sbin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/bin:/opt/homebrew/sbin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/bin:/opt/homebrew/sbin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/bin:/opt/homebrew/sbin:${NVM_DIR}/versions/node/v16.13.0/bin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/kitty.app/Contents/MacOS:${HOME}/bin:${HOME}/.config/bin:/usr/local/bin:/usr/local/sbin:usr/bin:/usr/sbin:${HOME}/bin:${HOME}/.config/bin:/usr/local/bin:/usr/local/sbin:usr/bin:/usr/sbin:${HOME}/bin:${HOME}/.config/bin:/usr/local/bin:/usr/local/sbin:usr/bin:/usr/sbin:${HOME}/bin:${HOME}/.config/bin:/usr/local/bin:/usr/local/sbin:usr/bin:/usr/sbin:${HOME}/bin:${HOME}/.config/bin:/usr/local/bin:/usr/local/sbin:usr/bin:/usr/sbin:${HOME}/bin:${HOME}/.config/bin:/usr/local/bin:/usr/local/sbin:usr/bin:/usr/sbin:${HOME}/bin:${HOME}/.config/bin:/usr/local/bin:/usr/local/sbin:usr/bin:/usr/sbin
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 5.1.12(1)-release (aarch64-apple-darwin21.1.0)'
uname -a: 'Darwin 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:41 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T6000 arm64'
checksum binary: 'sha256sum'
OS version: macOS 12.1 21C52
curl: /usr/bin/curl, curl 7.77.0 (x86_64-apple-darwin21.0) libcurl/7.77.0 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.42.0
wget: /opt/homebrew/bin/wget, GNU Wget 1.21.2 built on darwin21.1.0.
sed: /opt/homebrew/opt/gnu-sed/libexec/gnubin/sed
cut: /usr/bin/cut
basename: /usr/bin/basename
rm: /bin/rm (rm -i)
mkdir: /bin/mkdir
xargs: /opt/homebrew/opt/findutils/libexec/gnubin/xargs
git: /opt/homebrew/bin/git, git version 2.34.1
grep: /opt/homebrew/opt/grep/libexec/gnubin/grep, grep (GNU grep) 3.7
awk: /opt/homebrew/bin/awk, awk version 20180827
nvm current: system
which node: /opt/homebrew/bin/node
which iojs:
which npm: /opt/homebrew/bin/npm
npm config get prefix: /opt/homebrew
npm root -g: /opt/homebrew/lib/node_modules

nvm ls output:

       v12.14.1
       v16.13.0
->       system
default -> v16.13.0
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.13.0) (default)
stable -> 16.13 (-> v16.13.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.7 (-> N/A)
lts/fermium -> v14.18.2 (-> N/A)
lts/gallium -> v16.13.1 (-> N/A)

How did you install nvm?

Homebrew

What steps did you perform?

brew install nvm

What happened?

Worked

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

Yes, PATH is listed in the debug output above

@ljharb
Copy link
Member

ljharb commented Dec 15, 2021

nvm is explicitly unsupported when installed via homebrew; what happens if you try installing nvm with the install script?

In this case, it's probably that your homebrew-managed PATH isn't correctly allowing nvm's path to take precedence over /opt/homebrew/bin/, and i'm not sure how to fix that while still using homebrew for nvm (or node, for that matter)

@zigotica
Copy link
Author

OHMY, what an embarrassment, I cannot read. Yes, uninstalling brew nvm and running the official install from curl did the trick. Please accept my apologies, and thank you.

@ljharb ljharb added installing nvm Problems installing nvm itself non-issue / invalid This isn't relevant to nvm, or turned out to be something unrelated. labels Dec 16, 2021
@zigotica
Copy link
Author

zigotica commented Dec 16, 2021

Sorry, there must be somethign else. I unsinstalled the brew version, installed nvm through curl. I still cannot change versions, current appears to be "system"

$ nvm install 16.0.0
Downloading and installing node v16.0.0...
Downloading https://nodejs.org/dist/v16.0.0/node-v16.0.0-darwin-arm64.tar.xz...
############################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v16.0.0 (npm v8.1.4)

$ nvm use 16.0.0
Now using node v16.0.0 (npm v8.1.4)

$ nvm alias default 16.0.0
default -> 16.0.0 (-> v16.0.0)

$ nvm use default
Now using node v16.0.0 (npm v8.1.4)

$ nvm ls
        v16.0.0
       v16.10.0
       v16.13.0
->       system
default -> 16.0.0 (-> v16.0.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.13.0) (default)
stable -> 16.13 (-> v16.13.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.7 (-> N/A)
lts/fermium -> v14.18.2 (-> N/A)
lts/gallium -> v16.13.1 (-> N/A)


$ nvm current
system

Again my config:

$ nvm --version
0.39.0

$ which node
/opt/homebrew/bin/node

$ which npm
/opt/homebrew/bin/npm

$ npm config get prefix
/opt/homebrew

$ npm root -g
/opt/homebrew/lib/node_modules

I honestly dont know where more to look at. Yes, I restarted terminal, and even the computer.

@zigotica zigotica reopened this Dec 16, 2021
@zigotica
Copy link
Author

I am suspecting nvm (or some node versions installed through it) will not work in M1 macs. And I am not willing to use Rosetta. A solution I found is bypassing nvm altogether, and install a specific version of node through brew, but then I am obviously missing the whole point of nvm (no versions are possible, other that installing/uninstalling node every time I change project).

@ljharb
Copy link
Member

ljharb commented Dec 16, 2021

nvm works fine on M1 macs; but node itself doesn’t support m1 on less than v16 except with Rosetta.

@ljharb
Copy link
Member

ljharb commented Dec 16, 2021

It’s possibly 16.0.0 doesn’t support it; but 16 latest certainly does. There’s a whole section in nvm’s readme about it.

@zigotica
Copy link
Author

It’s possibly 16.0.0 doesn’t support it; but 16 latest certainly does. There’s a whole section in nvm’s readme about it.

Yeah, but same happens for v16.13.1, I still get the system response as if nvm is not used at all, which is driving me nuts.

@ljharb
Copy link
Member

ljharb commented Dec 16, 2021

In that case it’s likely a PATH issue. Make sure sourcing nvm is the last thing in your profile file; or at least, that it happens after the last thing that prepends to the path.

@zigotica
Copy link
Author

hold on, my problem is only inside tmux session! if I try nvm on a regular kitty tab it just works. inside tmux it does not... will investigate.

@zigotica
Copy link
Author

the super weird thing about it is that inside AND outside tmux,

$ node -p process.arch
arm64

@ljharb
Copy link
Member

ljharb commented Dec 16, 2021

What’s the PATH diff between inside and outside?

@zigotica
Copy link
Author

OUTSIDE TMUX:

$ echo $PATH
/Users/sergi/.nvm/versions/node/v16.0.0/bin:/opt/homebrew/opt/node@17/bin:/opt/homebrew/opt/node@16/bin:/opt/homebrew/opt/node@14/bin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/kitty.app/Contents/MacOS:/Users/sergi/bin:/Users/sergi/.config/bin:/usr/local/bin:/usr/local/sbin:usr/bin:/usr/sbin

$ which npm
/Users/sergi/.nvm/versions/node/v16.0.0/bin/npm

$ node -v
v16.13.1

INSIDE TMUX:

$ echo $PATH
/opt/homebrew/opt/node@17/bin:/opt/homebrew/opt/node@16/bin:/opt/homebrew/opt/node@14/bin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/sergi/.nvm/versions/node/v16.0.0/bin:/opt/homebrew/opt/node@17/bin:/opt/homebrew/opt/node@16/bin:/opt/homebrew/opt/node@14/bin:/opt/homebrew/opt/gnu-sed/libexec/gnubin:/opt/homebrew/opt/findutils/libexec/gnubin:/opt/homebrew/opt/grep/libexec/gnubin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/kitty.app/Contents/MacOS:/Users/sergi/bin:/Users/sergi/.config/bin:/usr/local/bin:/usr/local/sbin:usr/bin:/usr/sbin:/Users/sergi/bin:/Users/sergi/.config/bin:/usr/local/bin:/usr/local/sbin:usr/bin:/usr/sbin

$ which npm
/opt/homebrew/opt/node@16/bin/npm

$ node -v
v17.2.0

Going to look at those PATH changes as well. Thanks for all the help.

@ljharb
Copy link
Member

ljharb commented Dec 16, 2021

That strongly implies that whatever profile file tmux sources (that your regular shell doesn't) is doing more PATH stuff with homebrew's node after nvm is sourced.

(node shouldn't ever be installed with homebrew regardless, but it shouldn't interfere with nvm at all)

@zigotica
Copy link
Author

Yes, it's currently a mess. Most likely still artifacts from previous brew installs, since I was convinced brew was a viable option. I will try to remove all traces of nvm, npm, node, ... and reinstall nvm from curl/git again, to see if that helps. Thank you again.

@ljharb
Copy link
Member

ljharb commented Dec 16, 2021

I'll close this for now, but will immediately reopen it if there's something actionable for nvm. Happy to continue discussing regardless.

@ljharb ljharb closed this as completed Dec 16, 2021
@zigotica
Copy link
Author

zigotica commented Dec 16, 2021

I can confirm this is now working in/outside of tmux. I did:

  1. uninstall nvm, node, yarn
  2. install nvm via git
  3. add to path
  4. install node via nvm
  5. install yarn via brew

thank you again

@zigotica
Copy link
Author

OK, sorry to reopen this issue. I had this all solved, but after installing another brew formula (that has node as a dependency), I am back to original problem. Inside tmux, node version is the one of the node dependency installed by that formula, no matter if I previously had installed nvm using git.

Not sure how to avoid this (besides uninstalling every formula that might have node as a dependency, which is bummer)

thank you

@zigotica
Copy link
Author

OK, found this solution, but implies having to manually add each of node versions installed via nvm to the PATH, which is also a bummer.

@ljharb
Copy link
Member

ljharb commented Jan 11, 2022

Yeah that sucks a lot. I think a better solution is rearranging your profile file so that homebrew’s path ends up after nvm’s - iow, make sure nvm’s lines are last

@zigotica

This comment was marked as outdated.

@ljharb
Copy link
Member

ljharb commented Jan 11, 2022

Your PATH in nvm debug in the OP has /opt/homebrew/bin near the front. I think moving the homebrew paths to the end - or moving the nvm paths to the front - would do it.

@zigotica
Copy link
Author

I fixed the loop, I don't need to export each path, just prepend it.

Your PATH in nvm debug in the OP has /opt/homebrew/bin near the front. I think moving the homebrew paths to the end - or moving the nvm paths to the front - would do it.

No, really, my brew file is sourced before my nvm file, and brew's node version. Don't ask me why. The only solution for me was to force the loop above.

@zigotica
Copy link
Author

The reason why brew wins, is the way it creates the EXPORTs and PATH (the recommended way of doing so):

eval $(/opt/homebrew/bin/brew shellenv)

@ljharb
Copy link
Member

ljharb commented Jan 11, 2022

does that eval happen before or after the nvm lines?

@zigotica
Copy link
Author

does that eval happen before or after the nvm lines?

before

@ljharb
Copy link
Member

ljharb commented Jan 11, 2022

ok, then i don't understand why nvm isn't able to force its stuff to go in the front of the PATH. Do you have a default set? nvm alias default node?

@zigotica
Copy link
Author

ok, then i don't understand why nvm isn't able to force its stuff to go in the front of the PATH.

yeah, same here :)

Do you have a default set? nvm alias default node?

Yes, 16. But it doesn't matter, brew version (17) wins.

To be clear, it is working now, but it's a bit annoying to trace and discover. Just posted here so it can be tracked, for other people. Thank you again.

@brendabispo
Copy link

Try using:

arch -x86_64 zsh

Then try to install and run the nvm version you want. This will change the processor architecture to emulate old Intel chips.

reference

@igmrrf

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
installing nvm Problems installing nvm itself non-issue / invalid This isn't relevant to nvm, or turned out to be something unrelated.
Projects
None yet
Development

No branches or pull requests

4 participants