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

Installing NVM on macOS that's running zsh #2196

Closed
gd0st opened this issue Apr 18, 2020 · 12 comments
Closed

Installing NVM on macOS that's running zsh #2196

gd0st opened this issue Apr 18, 2020 · 12 comments
Labels
installing nvm: profile detection Issues with nvm's own install script, related to figuring out the right profile file. OS: Mac OS shell: zsh

Comments

@gd0st
Copy link

gd0st commented Apr 18, 2020

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?

@ljharb
Copy link
Member

ljharb commented Apr 19, 2020

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.

@ljharb ljharb added installing nvm: profile detection Issues with nvm's own install script, related to figuring out the right profile file. OS: Mac OS shell: zsh labels Apr 19, 2020
@sergiomedinaio
Copy link

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

@stephenjfox
Copy link

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

@ljharb
Copy link
Member

ljharb commented Jun 17, 2020

@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.

@stephenjfox
Copy link

stephenjfox commented Jun 17, 2020 via email

@asadakbar
Copy link
Contributor

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.

@ljharb
Copy link
Member

ljharb commented Jun 19, 2020

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

@asadakbar
Copy link
Contributor

@ljharb Sounds good. For now I've pushed up a pr for the documentation change here #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.

@steelcowboy
Copy link

Isn't this a duplicate of #2148?

@stephenjfox
Copy link

Isn't this a duplicate of #2148?

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

@steelcowboy
Copy link

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 :)

@stephenjfox
Copy link

Duplicate of #2148

@ljharb ljharb closed this as completed Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
installing nvm: profile detection Issues with nvm's own install script, related to figuring out the right profile file. OS: Mac OS shell: zsh
Projects
None yet
Development

No branches or pull requests

6 participants