Skip to content

NVM in fish #303

Open
Open
@ecbrodie

Description

@ecbrodie

How do I install NVM for the fish shell?

Activity

djensen47

djensen47 commented on Oct 14, 2013

@djensen47

May I request that this issue be reformatted in the form of a bug?

  • NVM does not install if you use the fish shell.
  • NVM does not work in the fish shell shell shell if previously installed in the bash shell. In fact, nvm isn't even in the path.
ljharb

ljharb commented on Apr 20, 2014

@ljharb
Member

I attempted to test this out - . nvm.sh didn't work in the fish shell, even with the shebang for /bin/sh or /bin/bash.

I'm not sure if a script can be portable across bash/sh/dash/ksh and still work in fish. For example, $? to indicate success doesn't work in fish, it's $status, which none of the other shells have.

Most worrying, all the other shells' function syntax doesn't work in fish. I suspect we'd need a brand new nvm.fish to make this work properly.

alex7kom

alex7kom commented on Apr 20, 2014

@alex7kom
Contributor

Not a self-promotion, but I did port nvm to fish, please check https://github.com/Alex7Kom/nvm-fish
I rewrote it entirely since fish is very different. If nvm.fish fits in the main nvm project, I'll be happy to contribute it.

ljharb

ljharb commented on Apr 20, 2014

@ljharb
Member

@alex7kom does your port share the same env vars and directory of node versions and global modules that standard nvm does?

alex7kom

alex7kom commented on Apr 20, 2014

@alex7kom
Contributor

@ljharb I tried to make it as close to standard nvm as possible, so it uses the same naming everywhere, and it should use the same directory of node versions if put in the same directory as standard nvm. However, I didn't update it for 4 months, so I'll need some time to achieve parity with nvm.
I hope I understood you right.

creationix

creationix commented on Apr 21, 2014

@creationix
Collaborator

@alex7kom This is great! I wanted to implement nvm for fish, but never found the time to learn fish well enough to do it. You are right that a complete rewrite was needed.

/me goes off to install fish and test it.

ljharb

ljharb commented on Apr 22, 2014

@ljharb
Member

@alex7kom Honestly, if you can commit to keeping your fish port up to date such that it can be a seamless drop-in for standard nvm, and i could simultaneously use installed nodes in one tab with a bash shell and another with a fish shell; they read the same .nvmrc files; and if it could use git-tagged versions; etc - what I'd prefer is for the install script to be able to intelligently install your fork rather than incorporate it into this repo.

Thoughts?

wires

wires commented on May 28, 2014

@wires

I tried it, works nice, thanks! 👍 Just a thought, python virtualenv provides bin/activate for bash-ish shells and bin/activate.fish for fish. If nvm could do something similar that would be nice. Also note that a .fish script could still use sh to delegate some work (installing etc) to the nvm bash version.

Globegitter

Globegitter commented on Aug 25, 2014

@Globegitter

https://github.com/Alex7Kom/nvm-fish has worked great for me. Would love to see the main project support fish out of the box at some point.

doughsay

doughsay commented on Jan 29, 2015

@doughsay

Sorry to dredge up an old issue, but with all the recent hype about io.js, and with the latest nvm now supporting installing io.js, this has become a bigger issue for fish users again. The latest version of the nvm-fish fork is woefully outdated compared to current nvm, and so therefore can't be used to install io.js. Has any more thought been put into this?

ljharb

ljharb commented on Jan 29, 2015

@ljharb
Member

There's a PR open to get it to work, but fish being wildly different than most shells, some of the changes required concern me. I'm still open to the possibility.

passcod

passcod commented on Feb 7, 2015

@passcod
Contributor

I've written a wrapper that lets fish people use nvm seamlessly: https://github.com/passcod/nvm-fish-wrapper 🐟

It works by running nvm in bash within a fish function, and doing some magic to pass the (relevant parts of the) environment through and export it again once nvm returns. Doing so incurs a noticeable delay (about 1 second) before nvm is run, but I think that's acceptable. Because it's just a wrapper, it will always work (unlike the nvm-fish port), requiring no maintenance while nvm can be updated at will, unless nvm changes significantly. Additionally, it uses the same nvm as other shells, so nodes (and ios) are shared (again, unlike the nvm-fish port). And it's less than two pagefuls of code ;P

It is similar in thought to #579 but less intrusive and requires no changes in nvm.

35 remaining items

eugenet8k

eugenet8k commented on Aug 25, 2017

@eugenet8k
osbre

osbre commented on Feb 11, 2020

@osbre

With this package installed, nvm works fine:

https://github.com/FabioAntunes/fish-nvm

elovin

elovin commented on Nov 18, 2021

@elovin

An alternative is to setup nvm in zsh/bash and then switch to fish (e.g. on mac): /bin/zsh -c "source ~/.zshrc && /usr/local/bin/fish -i"

ljharb

ljharb commented on Nov 18, 2021

@ljharb
Member

@elovin that wouldn’t leave nvm available inside fish to change the node version, which is the primary use case of nvm.

elovin

elovin commented on Dec 1, 2021

@elovin

@ljharb hm I'm not sure if I do something different in the setup then because I can switch between node versions just fine

Update:
You are right, I also use the workaround with bass, for some reason I still have to call zsh first though.

Toesandfeet

Toesandfeet commented on Mar 17, 2023

@Toesandfeet
alaslyalasel

alaslyalasel commented on Mar 17, 2023

@alaslyalasel
vladimiremi

vladimiremi commented on Jul 8, 2024

@vladimiremi
calle2010

calle2010 commented on Sep 19, 2024

@calle2010

I have written a fish function which basically executes nvm in a bash login shell and sets the path accordingly:
https://gist.github.com/calle2010/b3f0054c1d4b72394d0fda7f22d47b38
Since it modifies the $fish_users_paths variable the node installation is also available in a new shell without executing anything. So far this works for me.

kevinisaac

kevinisaac commented on Sep 20, 2024

@kevinisaac

Add the following to the fish config and restart the terminal (or reload the config):

function nvm
    bash -c "source ~/.nvm/nvm.sh; nvm $argv"
end
meotimdihia

meotimdihia commented on Sep 21, 2024

@meotimdihia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @danielb2@ljharb@creationix@passcod@alex7kom

        Issue actions

          NVM in fish · Issue #303 · nvm-sh/nvm