nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
79.08k stars 7.92k forks source link

Install cmd should pipe to zsh on OSX (not bash) #2508

Open LGraber opened 3 years ago

LGraber commented 3 years ago

Operating system and version:

OSX Catalina

How did you install nvm?

I tried to install following the steps in the README: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

However, it didn't update my .zshrc. I tried to follow the "troubleshooting" section but that also didn't help as even after making sure I had a .zshrc file, it didn't update it. I figured (apparently correctly) that the way to get it to update my zshrc file was to pipe to "zsh" and not "bash". After making that change everything appears to be working. Perhaps add this detail to the readme or update the install cmd.

```sh ```
ljharb commented 3 years ago

This has nothing to do with where it’s piped. The install script is written exclusively for bash and must never be ran on a different shell.

The install script should instead better figure out the default shell and its profile files.

LGraber commented 3 years ago

okay ... well, after trying other options to get it to work, I tried this and it "worked". Curious what is going to go wrong since it "must never" be run on a different shell but so far everything has been working. Am I going to be in trouble later?

ljharb commented 3 years ago

I mean, probably not, since the point of the install script is to get $NVM_DIR set up, and the right lines in your profile file - but I don’t test the install script on “not bash”.

A better long term solution is fixing the install script so that its behavior isn't influenced by which shell it uses, and also making it do the right thing for zsh users.

RCMainak commented 3 years ago

I believe I have a solution for this issue. PR incoming.

marcin-chwedczuk commented 3 years ago

I had the same problem (on Linux), I copy pasted the install oneliner to ZSH and it does not updated my .zshrc file. Manually adding the mentioned in README.md lines to ~/.zshrc helps:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
loughlincodes commented 3 years ago

Marcin's solution above

I had the same problem (on Linux), I copy pasted the install oneliner to ZSH and it does not updated my .zshrc file. Manually adding the mentioned in README.md lines to ~/.zshrc helps:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

works well on Mac OS X.15.7 using ZSH. In fact, it saved me quite a bit of hassle so thank you @marcin-chwedczuk