Skip to content

NVM in fish #303

Description

@ecbrodie

How do I install NVM for the fish shell?

Activity

  1. 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.
  2. 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.

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

  4. 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?

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

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

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

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

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

  10. 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?

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

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

  13. added a commit that references this issue on Feb 7, 2015
  14. edc commented on Jul 13, 2015

    @edc

    I also wrote a general wrapper to bring almost any bash utility to fish shell: https://github.com/edc/bass. It works flawlessly with nvm using syntax like bass source ~/.nvm/nvm.sh \; nvm --version. For convenience, one can create an alias Fish function:

    function nvm
          bass source ~/.nvm/nvm.sh ';' nvm $argv
      end
    

    and then just use nvm --version, nvm ls, etc.

  15. 24 remaining items

  16. derekjkeller commented on Apr 19, 2016

    @derekjkeller
    Contributor

    @shangsunset wrong derek referenced in your comment earlier, but he obviously saw it.

  17. danielb2 commented on Jan 27, 2017

    @danielb2
    Contributor

    I just use

    #!/bin/bash
    
    export NVM_SYMLINK_CURRENT=true
    
    if [[ -s $HOME/.nvm/nvm.sh ]] ;
      then
        source $HOME/.nvm/nvm.sh;
      else
        echo "No nvm found in `$HOME/.nvm/nvm.sh`";
    fi
    
    nvm $@

    And then add /usr/local/sbin $HOME/.nvm/current/bin to my path. This is why I implemented the NVM_SYMLINK_CURRENT variable for nvm in the first place

  18. eugene-tea commented on Aug 25, 2017

    @eugene-tea
  19. osbre commented on Feb 11, 2020

    @osbre

    With this package installed, nvm works fine:

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

  20. 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"

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

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

  23. Toesandfeet commented on Mar 17, 2023

    @Toesandfeet
  24. alaslyalasel commented on Mar 17, 2023

    @alaslyalasel
  25. vladimiremi commented on Jul 8, 2024

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

  27. 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
  28. meotimdihia commented on Sep 21, 2024

    @meotimdihia
  29. altendky commented on Sep 9, 2025

    @altendky

    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

    this does indeed work well enough to execute nvm. however, be aware that it does not propagate out the PATH mutation of nvm use, for example. with the nvm interface being shell functions, it can end up doing things you don't expect if you mostly deal with 'programs' instead.

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

      Issue actions