Nvm: Installing NVM on macOS that's running zsh

Created on 18 Apr 2020  ·  12Comments  ·  Source: nvm-sh/nvm

Operating system and version:

macOS 10.15.4

How did you install nvm?


When I was trying to install nvm from a fresh macOS install, the terminal would not recognize the command so here is what I did and I hope it can help other people maybe. I could also use some opinions if this is ok to do.

What steps did you perform?

touch ~/.bash_profile
Then I ran the curl installation command
touch ~/.zshrc
Please use a single > if you're trying to append .zshrc otherwise you will wipe all the contents of .zshrc if you don't.
cat ~/.bash_profile >> ~/.zschrc

What happened?

It worked for me and I was able to update node.

Can I get some comments on if this is a good work around to get nvm to work?

Mac OS profile detection zsh

Most helpful comment

TL;DR - Explicitly set the profile you want to use by setting the env var PROFILE to the profiles file path, then run the install script.

I hit this same issue where nvm kept trying to update .bashrc instead of .zshrc. I read through the install script and it utilizes an explicitly set $PROFILE before looking for profile files. So I set the PROFILE environment variable by running export PROFILE=~/.zshrc in the terminal and reran the install script which properly updated .zshrc. I'm being explicit for those who may not understand what to do.

The above got me past the issue, but it doesn' make sense to me why the install script didn't set zsh as my shell. https://github.com/nvm-sh/nvm/blob/master/install.sh#L236 looks for $BASH_VERSION, and if it doesn't find that moves on to look for $ZSH_VERSION. It bases which profile to use based on whichever of these is set. I only have $ZSH_VERSION set, so .zshrc should have been used. Because the conditional is checking for $BASH_VERSION first, I imagine that is what is tripping up some people who also have that set but are using zsh. I know very little about shell scripting otherwise I'd dive in.

Instead of relying on these env vars, you could look at what $SHELL returns. That would give you a much cleaner signal for which profile file to use.

Hope this helps.

All 12 comments

That seems fine to me. If you have ~/.bash_profile present when zsh is meant to be the default, then the install script is likely to get confused and think you want bash.

It only work for me when I migrate lines in .bash_profile into .zschrc and remove .bash_profile, otherwise it didn't load properly.

I had the same experience at @sergiomedinaio. I recommend making the code change or updating the docs.
What's the preference for this community? @ljharb

@stephenjfox my preference would be that the install script does the right thing; if that's not practical, then the docs should be updated.

In either case a PR is appreciated.

👍I'll see what I can do this weekend

2020년 6월 17일 (수) 오전 3:24, Jordan Harband notifications@github.com님이 작성:

@stephenjfox https://github.com/stephenjfox my preference would be that
the install script does the right thing; if that's not practical, then the
docs should be updated.

In either case a PR is appreciated.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/nvm-sh/nvm/issues/2196#issuecomment-645201485, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/ABPWKJLSYPAN3L2CJX4GGH3RXBVUDANCNFSM4MLFLEKA
.

TL;DR - Explicitly set the profile you want to use by setting the env var PROFILE to the profiles file path, then run the install script.

I hit this same issue where nvm kept trying to update .bashrc instead of .zshrc. I read through the install script and it utilizes an explicitly set $PROFILE before looking for profile files. So I set the PROFILE environment variable by running export PROFILE=~/.zshrc in the terminal and reran the install script which properly updated .zshrc. I'm being explicit for those who may not understand what to do.

The above got me past the issue, but it doesn' make sense to me why the install script didn't set zsh as my shell. https://github.com/nvm-sh/nvm/blob/master/install.sh#L236 looks for $BASH_VERSION, and if it doesn't find that moves on to look for $ZSH_VERSION. It bases which profile to use based on whichever of these is set. I only have $ZSH_VERSION set, so .zshrc should have been used. Because the conditional is checking for $BASH_VERSION first, I imagine that is what is tripping up some people who also have that set but are using zsh. I know very little about shell scripting otherwise I'd dive in.

Instead of relying on these env vars, you could look at what $SHELL returns. That would give you a much cleaner signal for which profile file to use.

Hope this helps.

@asadakbar a PR to improve the install script would be most welcome

@ljharb Sounds good. For now I've pushed up a pr for the documentation change here https://github.com/nvm-sh/nvm/pull/2241

Followup to my comment above, I believe the reason why the install script did not do what I expected was because I ran the curl command as the readme stated, as piped into bash. That set $BASH_VERSION even though I was running zsh at the time.

Isn't this a duplicate of #2148?

Isn't this a duplicate of #2148?

Didn't see it when I made mine. Would be glad to transition over there

No worries! Yeah just comment on that issue if you have any thing to add from here, and then add the comment Duplicate of #2148 to this one and close it :)

Duplicate of #2148

Was this page helpful?
0 / 5 - 0 ratings