jorgebucaran / nvm.fish

The Node.js version manager you'll adore, crafted just for Fish
https://git.io/nvm.fish
MIT License
2.06k stars 69 forks source link

`nvm_default_version` not working to set default version of node #187

Closed prevuelta closed 2 years ago

prevuelta commented 2 years ago

nvm_default_version doesn't work for me on MacOS Big Sur running fish shell, new shell always reverts to older version

jorgebucaran commented 2 years ago

What exactly did you do that "didn't work"? What Fish version are you on?

nvm_default_version is a universal variable. Did you set it like so?

moritzreiter commented 2 years ago

I think I might have the same problem and could be able to give some more detailed information.

So, I have two node versions installed: the most recent via homebrew and the current LTS version via nvm:

❯ nvm list
     system
 ▶ v16.15.0 lts/gallium

I set nvm_default_version like this:

❯ set --universal nvm_default_version lts/gallium

Then, in a new shell, nvm says that lts/gallium is active, but node --version tells me something else:

❯ nvm current
v16.15.0

❯ node --version
v18.3.0

Oddly enough, when in this state, even explicitly switching to the LTS version doesn't work anymore:

❯ nvm use lts
Now using Node v18.3.0 (npm 8.11.0) /opt/homebrew/Cellar/node/18.3.0/bin/node

I'll have to first explicitly switch to the system version and then again to lts, in order to make it happen:

❯ nvm use system
Now using Node v18.3.0 (npm 8.11.0) /opt/homebrew/Cellar/node/18.3.0/bin/node
❯ nvm use lts
Now using Node v16.15.0 (npm 8.5.5) ~/.local/share/nvm/v16.15.0/bin/node
❯ node --version
v16.15.0

Oh, and here are the fish and nvm versions I'm using:

❯ fish --version
fish, version 3.4.1

❯ nvm --version
nvm, version 2.2.9
jorgebucaran commented 2 years ago

Are any of you prepending the homebrew path, e.g., /opt/homebrew/bin to your $PATH in config.fish?

Because that would take precedence over nvm.fish (since config.fish runs last).

Use fish_add_path /opt/homebrew/bin in config.fish or, interactively, set -U fish_user_paths to your homebrew path.

kijz commented 2 years ago

Hey, im encountering the same problem. I am running the following command in my config.fish eval "$(/opt/homebrew/bin/brew shellenv)"

adding the fish path did not work for me. Do you have any idea how to work around this?

Do you maybe know a better way to integrate homebrew so that my config does not break?

moritzreiter commented 2 years ago

@jorgebucaran Yes, you're right. I also had eval (/opt/homebrew/bin/brew shellenv) in my config.fish, so that /opt/homebrew/bin always was the first entry in my $PATH after starting a new shell. Thanks a lot for the hint!

@fkajzer Putting fish_add_path /opt/homebrew/bin in config.fish also didn't work for me, because that way, /opt/homebrew/bin will still get prepended to the $PATH. But it's also not necessary.

Just run

fish_add_path /opt/homebrew/bin /opt/homebrew/sbin

once. It adds the entries to $fish_user_paths, which is a universal variable and therefore the entries will persist even without setting it in the fish config.

jorgebucaran commented 2 years ago

Yes, using fish_add_path /opt/homebrew/bin (once) interactively is the correct answer. You could set fish_user_paths yourself too, but you'd want to make sure that you are not creating a repeated entry.

@anothernode Thank you for pointing out that fish_add_path in config.fish wouldn't fix the issue.