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

fnm use doesn't switch node version #92

Closed
spiroid opened this issue Apr 10, 2019 · 32 comments
Closed

fnm use doesn't switch node version #92

spiroid opened this issue Apr 10, 2019 · 32 comments
Labels
bug Something isn't working fish shell

Comments

@spiroid
Copy link

spiroid commented Apr 10, 2019

Hi,

With a clean install of fnm 1.9.0 and fish shell version 3.0.2, the fnm use command doesn't work as expected.

steps to reproduce

$ fnm install v8.10.0
$ fnm use v8.10.0
$ fnm alias v8.10.0 default

fnm ls is just fine

$ fnm ls
The following versions are installed:
* v8.10.0 (default)

And Testing node version gives the expected output

$ node --version
v8.10.0

Now installing latest LTS 10.15.3 and trying to switch to that version is not working

fnm install v10.15.3
fnm use v10.15.3

Again, fnm ls says that everything is fine

$ fnm ls
The following versions are installed:
* v8.10.0 (default)
* v10.15.3

(with a blue-green highlight on the 10.15.3 version indicating it's the current version)

However node version is still 8.10.0

$ node --version
v8.10.0

Additional information

I've tried to locate which version is pointing the node symbolic link to:

$ which node
/tmp/fnm-shell-2857505/bin/node

And /tmp/fnm-shell-2857505 is linking /tmp/fnm-shell-2857505 -> /home/spiroid/.fnm/aliases/default/ which seems to be the issue here, as i guess it should link /home/spiroid/.fnm/current/ right ?

Thanks for your help

@Schniz
Copy link
Owner

Schniz commented Apr 20, 2019

Hey! Can you please try 1.9.1 and see if it fixes that?

@davidosomething
Copy link

The path is updated if you do echo $PATH but in zsh I had to do a rehash after every switch to get it to actually use that path

@Schniz
Copy link
Owner

Schniz commented May 4, 2019

It is very weird, and I'm very sorry it happens to you.
I just tried it on a new installation in Fish and it does work. Are you sure that's the problem? can you please record it with asciinema so we'll see what's going on?

@VincentCordobes
Copy link

VincentCordobes commented May 31, 2019

Same for me when switching node version via fnm use. I need to eval "$(fnm env --multi)" to apply it

Note that I use fnm 1.11.0

@Schniz
Copy link
Owner

Schniz commented May 31, 2019

Can you show me a shell that runs the following?

fnm env --multi | source

echo "-> NODE: "(which node)
echo "-> VER: "(node -v)
echo "-> PATH: $PATH"
env | grep FNM

fnm ls
fnm use <YOUR VERSION HERE>

echo "-> NODE: "(which node)
echo "-> VER: "(node -v)
echo "-> PATH: $PATH"
env | grep FNM

I can't get it to fail on my machine - but maybe this will help me 😄

@Schniz
Copy link
Owner

Schniz commented May 31, 2019

I hope I got the fish syntax right!

@Schniz Schniz added fish shell bug Something isn't working labels Jun 3, 2019
@VincentCordobes
Copy link

Ok that's weird, I didn't change anything and now it is working as expected (btw I am using zsh) @Schniz

@dncrews
Copy link

dncrews commented Jun 3, 2019

I had the same problem using fnm installed via the bash script in ZSH. I deleted it and reinstalled it using the homebrew installation, and it's working now. 🤷‍♂

@Schniz
Copy link
Owner

Schniz commented Jun 3, 2019

Maybe there was a weird error on a previous version of the installation script?
This has to be well tested. It isn’t. I’m sorry about that!

@cem2ran
Copy link

cem2ran commented Jun 11, 2019

I've just run into the same issue running the script in bash on linux (debian).

@Schniz
Copy link
Owner

Schniz commented Jun 11, 2019

Sorry about that. can you run the following commands and report the output?

echo "PATH=$PATH"
env | grep FNM_
echo "node in $(which node)"
echo "find:"
find $FNM_DIR -maxdepth 2

@cem2ran
Copy link

cem2ran commented Jun 11, 2019

That was pretty helpful actually! I realized the issue is because linuxbrew inserted its init script in ~/.profile, which loads bashrc followed by linuxbrew init. Node was initially installed via linuxbrew, which then became the default no matter what I did with fnm.

@Schniz
Copy link
Owner

Schniz commented Jun 11, 2019

Ohhh, that looks like a common issue. I wonder if we can implement a fnm doctor command that will search in your PATH for node before FNM and alert for that, and maybe also provide the output for the commands above 😄

@Schniz
Copy link
Owner

Schniz commented Jul 14, 2019

Closing for inactivity

@Schniz Schniz closed this as completed Jul 14, 2019
@perkrlsn
Copy link

I have the same issue, but I refuse going back to nvm because it's just so slow and I love the speed of fnm :)

I ended up doing something like this (since I'm not very good at bash/zsh), rehashing on each fnm use seems to solve it.

#FNM
eval "`fnm env --multi`"

#FNM autoload
autoload -U add-zsh-hook
    _fnm_autoload_hook () {
        if [[ -f .node-version && -r .node-version ]]; then
	    echo "fnm: Found .node-version"
	    fnm use
	    rehash
        elif [[ -f .nvmrc && -r .nvmrc ]]; then
	    echo "fnm: Found .nvmrc"
	    fnm use
	    rehash
        else
	    fnm use system --quiet
	    rehash
	fi
    }

add-zsh-hook chpwd _fnm_autoload_hook && _fnm_autoload_hook

@Schniz
Copy link
Owner

Schniz commented Dec 11, 2019

hmmm, which zsh are you running? what's your setup?

@Vinlock
Copy link

Vinlock commented May 11, 2021

That code snippet seems out of date and I can't seem to see how to auto rehash after changing :(

@Schniz
Copy link
Owner

Schniz commented May 11, 2021

@Vinlock What do you mean?
This is the whole point of fnm. What are you experiencing?

@Vinlock
Copy link

Vinlock commented May 11, 2021

@Schniz thanks for the reply!

I'm running zsh and I added

# FNM
eval "$(fnm env)"

to my ~/.zshrc file.

After sourcing the ~.zshrc file. I do the following with the following result:

➜ fnm use 10
Using Node v10.24.1

➜ node -v
v15.14.0

Did I miss something?

@Schniz
Copy link
Owner

Schniz commented May 11, 2021

can you share echo $PATH with me? 😁

@Vinlock
Copy link

Vinlock commented May 11, 2021

Nevermind 🤦🏼 . I guess I had to restart iTerm as even though I had done source ~/.zshrc.

It's working great now, and wow it's incredibly faster than nvm 😮 .

➜ node -v
v15.14.0

➜ fnm use 10
Using Node v10.24.1

➜ node -v
v10.24.1

Thanks for your time!

@Schniz
Copy link
Owner

Schniz commented May 11, 2021

haha all good! happy that it works for you 😃
next time you can: source ~/.zshrc and call it a day. Or open a new tab, and close the older one 😃

@Vinlock
Copy link

Vinlock commented May 11, 2021

haha all good! happy that it works for you 😃
next time you can: source ~/.zshrc and call it a day. Or open a new tab, and close the older one 😃

Yeah, I had done the source command and it didn't effect anything it seemed for some reason. Though restarting iTerm made it work. New tab may have done the trick too. Just wondering what else it needed aside from source ~/.zshrc 🤔

@Schniz
Copy link
Owner

Schniz commented May 12, 2021

maybe you still had nvm installed on the current shell. I believe there is precedence for Bash functions over $PATH executables

@redeemefy
Copy link

I guess my issue belongs here instead
#370 (comment)

@spiroid
Copy link
Author

spiroid commented Apr 1, 2022

I never took the time to give some feedback here and I'm sorry for that.
I gave fnm another try recently and it perfectly works and I no longer have this issue!
Thanks a lot for your work 💯

@timodempwolf
Copy link

timodempwolf commented Jul 18, 2022

I am still facing this issue. I have to use rehash to make this version stick.

╭─timod@cw-laptop ~ 
╰─$ node --version
v16.16.0
╭─timod@cw-laptop ~ 
╰─$ fnm use 18
Using Node v18.6.0
╭─timod@cw-laptop ~ 
╰─$ node --version
v16.16.0
╭─timod@cw-laptop ~ 
╰─$ fnm --version
fnm 1.31.0
╭─timod@cw-laptop ~ 
╰─$ rehash
╭─timod@cw-laptop ~ 
╰─$ node --version
v18.6.0

@a-shtubov
Copy link

I ran into the same problem. Every node version switch required rehash in my zsh shell. Turned out the problem was that no default node version was set in fnm. Once I ran fnm default x.x.x versions started switching correctly

@therosbif
Copy link

therosbif commented Mar 5, 2023

For anyone having an issue with fnm conflicting with homebrew's installation of node on fish I fixed it by moving the following line from ~/.config/fish/config.fish to ~/.config/fish/conf.d/brew.fish:

# ~/.config/fish/conf.d/brew.fish
export PATH="/opt/homebrew/sbin:/opt/homebrew/bin:$PATH"

@orlandosh
Copy link

I ran into the same problem. Every node version switch required rehash in my zsh shell. Turned out the problem was that no default node version was set in fnm. Once I ran fnm default x.x.x versions started switching correctly

The same happens to me. But I intentionally want to use system as default. If I set 20 as default, it switches to 14 when needed. If I set system as default, I need to use rehash every time, even if I manually enter fnm use 14.

To keep up with the latest node version, I prefer using system as dnf takes care of it, and then I only use fnm for project-specific requirements.

Does anyone have an idea why I need rehash when fnm default is set to system?

@luisManuel03
Copy link

I have this error on a Windows computer when I try to use "fnm use": "error: We cannot find the environment variables needed to replace the Node version." And even placing the environment variable "FNM_DIR" in the "path" I get the same problem and I don't know what to do. Does someone know how to solve this problem? I would appreciate it very much

@atzezitman
Copy link

atzezitman commented Jun 5, 2024

I have this error on a Windows computer when I try to use "fnm use": "error: We cannot find the environment variables needed to replace the Node version." And even placing the environment variable "FNM_DIR" in the "path" I get the same problem and I don't know what to do. Does someone know how to solve this problem? I would appreciate it very much

I had "We can't find the necessary environment variables to replace the Node version."

  1. Run "fnm env"
    Outputs: SET PATH=C:\....

  2. Either:
    A) Copy/paste the output in the same prompt. And you are good to go. Though you will always need to repeat this for each new command prompt.
    B) Follow https://www.computerhope.com/issues/ch000549.htm to add those environment variables by hand. You will need to restart your command prompt only once.
    C) Use SETX instead of SET to persist these variables on your local machine. Note, remove the = sign and double quote the values that contain spaces. You will need to restart your command prompt only once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fish shell
Projects
None yet
Development

No branches or pull requests