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

NVM in fish #303

Open
ecbrodie opened this issue Oct 10, 2013 · 46 comments
Open

NVM in fish #303

ecbrodie opened this issue Oct 10, 2013 · 46 comments

Comments

@ecbrodie
Copy link

How do I install NVM for the fish shell?

@djensen47
Copy link

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
Copy link
Member

ljharb commented Apr 20, 2014

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
Copy link
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
Copy link
Member

ljharb commented Apr 20, 2014

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

@alex7kom
Copy link
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
Copy link
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
Copy link
Member

ljharb commented Apr 22, 2014

@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
Copy link

wires commented May 28, 2014

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
Copy link

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.

@ghost ghost mentioned this issue Nov 15, 2014
@doughsay
Copy link

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
Copy link
Member

ljharb commented Jan 29, 2015

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
Copy link
Contributor

passcod commented Feb 7, 2015

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.

ljharb added a commit that referenced this issue Feb 7, 2015
Update README: Point fish users in the right direction (relates to #303)
@edc
Copy link

edc commented Jul 13, 2015

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.

@passcod
Copy link
Contributor

passcod commented Jul 13, 2015

@edc This is really cool! Does it work as well on linux and on OS X? If so I'll post a notice on nvm-fish-wrapper to use bass instead.

@edc
Copy link

edc commented Jul 13, 2015

@passcod I only tested it on OS X. Should work on Linux. It probably does not work on Windows.

passcod added a commit to passcod/nvm-fish-wrapper that referenced this issue Jul 25, 2015
Thanks to @edc for creating bass.

Thanks to @lnikkila and @brandonweiss for code contributions.

Thanks to @keithamus, @externl, @blazeworx, @taktran, @jkarttunen, @jakubholynet, @doughsay, @alex7kom, @msx, @steve-ross, @leebrooks0, @nanoxd, @tomekiwi, @randyschneck, @jadengore, as well as the contributors above for reporting bugs and helping out in the issue threads.

Thanks also to all stargazers not mentioned above: @Globegitter, @luhmann, @oahziur, @mike-engel, @yamafaktory, @footearth, @pborenstein, @ceejbot (famous npm people starring my work! *o*), @plord, @sobering, @matthewspencer, @rossluebe, @d6u, @arnaudsj, @jney, @arbourd, @jeromecovington, @mhamann, @kompot, @cryptoquick, @sarkian, @blissdev, @Thimoteus, @eush77, @dd1994, @berkus, @judasnow, @paulriddle, @giodamelio, @ScottMaclure, @deepsweet, @Maxim-Tuvanov, @CarterTsai, @Lordnibbler, @ismay, @OtaK, @nicksergeant, @SeeThruHead, @halhenke, @jerray, @therocketforever, @colinmeinke, @MadMub, @barberousse, @karlbateman, @benmarten, @mistadikay, @AdamCanady, @bheesham, @jboulouloubi, @moretti, @adri, @RFS4ever, @hcevns, @zhongxingdou, @marceloboeira, @musically-ut, @fuzetsu, @makotot, @tomekwi, @jeffbcross (dear me, an Angular.js committer?! *o*), @olessavluk, @imposibrus, @AndreTheHunter, @volodymyrkoval, @denji, @nemoDreamer, @legatoo, @atesgoral, @ThomWright, @jcrben, @ZuraGuerra, @andyklimczak, @Nek, @a1ip, @alfredooo, @passerbyid, @dariuszdziuk (hello Spotify, listening with you right this moment), @lordzfc, @StepanKuzmin, @joshhunt, @daniel-shin1104, @michalmarczyk, and @knappg.

Thanks to @creationix for creating NVM.

Thanks to all those on the nvm-sh/nvm#303 thread.

Thanks to @alxcenz for being a constant inspiration and a friend.

Thanks to @makoConstruct for visions of a better future.

Thanks to all of Merveilles for reasons.

Thanks to Saf for being a bright star shining always.

Thanks to Léa. Je t'aime.

Thanks to my parents for letting me code until the wee hours of the morning. To Dad for giving me help with Logo. That turtle is the best thing that's happened to my programming.

Thanks to all you awesome people, past present and future.

…okay, that got long and involved and a bit over the top. It's been humbling to have all these people on a project. Have a good day, friends.
bbuck added a commit to bbuck/nvm that referenced this issue Aug 6, 2015
Adds information about bass to the README which is directly recommended by nvm-fish-wrapper and can support iojs (unlike nvm-fish), this is in relation to Issue nvm-sh#303.
passcod added a commit to passcod/nvm-fish-wrapper that referenced this issue Aug 15, 2015
Thanks to @edc for creating bass.

Thanks to @lnikkila and @brandonweiss for code contributions.

Thanks to @keithamus, @externl, @blazeworx, @taktran, @jkarttunen, @jakubholynet, @doughsay, @alex7kom, @msx, @steve-ross, @leebrooks0, @nanoxd, @tomekiwi, @randyschneck, @jadengore, as well as the contributors above for reporting bugs and helping out in the issue threads.

Thanks also to all stargazers not mentioned above: @Globegitter, @luhmann, @oahziur, @mike-engel, @yamafaktory, @footearth, @pborenstein, @ceejbot (famous npm people starring my work! *o*), @plord, @sobering, @matthewspencer, @rossluebe, @d6u, @arnaudsj, @jney, @arbourd, @jeromecovington, @mhamann, @kompot, @cryptoquick, @sarkian, @blissdev, @Thimoteus, @eush77, @dd1994, @berkus, @judasnow, @paulriddle, @giodamelio, @ScottMaclure, @deepsweet, @Maxim-Tuvanov, @CarterTsai, @Lordnibbler, @ismay, @OtaK, @nicksergeant, @SeeThruHead, @halhenke, @jerray, @therocketforever, @colinmeinke, @MadMub, @barberousse, @karlbateman, @benmarten, @mistadikay, @AdamCanady, @bheesham, @jboulouloubi, @moretti, @adri, @RFS4ever, @hcevns, @zhongxingdou, @marceloboeira, @musically-ut, @fuzetsu, @makotot, @tomekwi, @jeffbcross (dear me, an Angular.js committer?! *o*), @olessavluk, @imposibrus, @AndreTheHunter, @volodymyrkoval, @denji, @nemoDreamer, @legatoo, @atesgoral, @ThomWright, @jcrben, @ZuraGuerra, @andyklimczak, @Nek, @a1ip, @alfredooo, @passerbyid, @dariuszdziuk (hello Spotify, listening with you right this moment), @lordzfc, @StepanKuzmin, @joshhunt, @daniel-shin1104, @michalmarczyk, and @knappg.

Thanks to @creationix for creating NVM.

Thanks to all those on the nvm-sh/nvm#303 thread.

Thanks to @alxcenz for being a constant inspiration and a friend.

Thanks to @makoConstruct for visions of a better future.

Thanks to all of Merveilles for reasons.

Thanks to Saf for being a bright star shining always.

Thanks to Léa. Je t'aime.

Thanks to my parents for letting me code until the wee hours of the morning. To Dad for giving me help with Logo. That turtle is the best thing that's happened to my programming.

Thanks to all you awesome people, past present and future.

…okay, that got long and involved and a bit over the top. It's been humbling to have all these people on a project. Have a good day, friends.
passcod added a commit to passcod/nvm-fish-wrapper that referenced this issue Aug 16, 2015
Thanks to @edc for creating bass.

Thanks to @lnikkila and @brandonweiss for code contributions.

Thanks to @keithamus, @externl, @blazeworx, @taktran, @jkarttunen, @jakubholynet, @doughsay, @alex7kom, @msx, @steve-ross, @leebrooks0, @nanoxd, @tomekiwi, @randyschneck, @jadengore, as well as the contributors above for reporting bugs and helping out in the issue threads.

Thanks also to all stargazers not mentioned above: @Globegitter, @luhmann, @oahziur, @mike-engel, @yamafaktory, @footearth, @pborenstein, @ceejbot (famous npm people starring my work! *o*), @plord, @sobering, @matthewspencer, @rossluebe, @d6u, @arnaudsj, @jney, @arbourd, @jeromecovington, @mhamann, @kompot, @cryptoquick, @sarkian, @blissdev, @Thimoteus, @eush77, @dd1994, @berkus, @judasnow, @paulriddle, @giodamelio, @ScottMaclure, @deepsweet, @Maxim-Tuvanov, @CarterTsai, @Lordnibbler, @ismay, @OtaK, @nicksergeant, @SeeThruHead, @halhenke, @jerray, @therocketforever, @colinmeinke, @MadMub, @barberousse, @karlbateman, @benmarten, @mistadikay, @AdamCanady, @bheesham, @jboulouloubi, @moretti, @adri, @RFS4ever, @hcevns, @zhongxingdou, @marceloboeira, @musically-ut, @fuzetsu, @makotot, @tomekwi, @jeffbcross (dear me, an Angular.js committer?! *o*), @olessavluk, @imposibrus, @AndreTheHunter, @volodymyrkoval, @denji, @nemoDreamer, @legatoo, @atesgoral, @ThomWright, @jcrben, @ZuraGuerra, @andyklimczak, @Nek, @a1ip, @alfredooo, @passerbyid, @dariuszdziuk (hello Spotify, listening with you right this moment), @lordzfc, @StepanKuzmin, @joshhunt, @daniel-shin1104, @michalmarczyk, and @knappg.

Thanks to @creationix for creating NVM.

Thanks to all those on the nvm-sh/nvm#303 thread.

Thanks to @alxcenz for being a constant inspiration and a friend.

Thanks to @makoConstruct for visions of a better future.

Thanks to all of Merveilles for reasons.

Thanks to Saf for being a bright star shining always.

Thanks to Léa. Je t'aime.

Thanks to my parents for letting me code until the wee hours of the morning. To Dad for giving me help with Logo. That turtle is the best thing that's happened to my programming.

Thanks to all you awesome people, past present and future.

…okay, that got long and involved and a bit over the top. It's been humbling to have all these people on a project. Have a good day, friends.
@derekstavis
Copy link
Contributor

If you use Oh My Fish framework you can use foreign-env to run nvm just like bass does. In fact, the plugin is a rewrite of bass in pure fish :)

passcod added a commit to passcod/nvm-fish-wrapper that referenced this issue Sep 26, 2015
Thanks to @edc for creating bass.

Thanks to @lnikkila and @brandonweiss for code contributions.

Thanks to @keithamus, @externl, @blazeworx, @taktran, @jkarttunen, @jakubholynet, @doughsay, @alex7kom, @msx, @steve-ross, @leebrooks0, @nanoxd, @tomekiwi, @randyschneck, @jadengore, as well as the contributors above for reporting bugs and helping out in the issue threads.

Thanks also to all stargazers not mentioned above: @Globegitter, @luhmann, @oahziur, @mike-engel, @yamafaktory, @footearth, @pborenstein, @ceejbot (famous npm people starring my work! *o*), @plord, @sobering, @matthewspencer, @rossluebe, @d6u, @arnaudsj, @jney, @arbourd, @jeromecovington, @mhamann, @kompot, @cryptoquick, @sarkian, @blissdev, @Thimoteus, @eush77, @dd1994, @berkus, @judasnow, @paulriddle, @giodamelio, @ScottMaclure, @deepsweet, @Maxim-Tuvanov, @CarterTsai, @Lordnibbler, @ismay, @OtaK, @nicksergeant, @SeeThruHead, @halhenke, @jerray, @therocketforever, @colinmeinke, @MadMub, @barberousse, @karlbateman, @benmarten, @mistadikay, @AdamCanady, @bheesham, @jboulouloubi, @moretti, @adri, @RFS4ever, @hcevns, @zhongxingdou, @marceloboeira, @musically-ut, @fuzetsu, @makotot, @tomekwi, @jeffbcross (dear me, an Angular.js committer?! *o*), @olessavluk, @imposibrus, @AndreTheHunter, @volodymyrkoval, @denji, @nemoDreamer, @legatoo, @atesgoral, @ThomWright, @jcrben, @ZuraGuerra, @andyklimczak, @Nek, @a1ip, @alfredooo, @passerbyid, @dariuszdziuk (hello Spotify, listening with you right this moment), @lordzfc, @StepanKuzmin, @joshhunt, @daniel-shin1104, @michalmarczyk, and @knappg.

Thanks to @creationix for creating NVM.

Thanks to all those on the nvm-sh/nvm#303 thread.

Thanks to @alxcenz for being a constant inspiration and a friend.

Thanks to @makoConstruct for visions of a better future.

Thanks to all of Merveilles for reasons.

Thanks to Saf for being a bright star shining always.

Thanks to Léa. Je t'aime.

Thanks to my parents for letting me code until the wee hours of the morning. To Dad for giving me help with Logo. That turtle is the best thing that's happened to my programming.

Thanks to all you awesome people, past present and future.

…okay, that got long and involved and a bit over the top. It's been humbling to have all these people on a project. Have a good day, friends.
@estebanprimost
Copy link

@derekstavis That's a great tip, thanks. With bass I have some troubles, but with fish functions + foreign-env it works!:

# ~/.config/fish/functions/nvm.fish
# $NVM_DIR=your nvm install path
function nvm
    fenv source $NVM_DIR/nvm.sh \; nvm $argv
end

@derekstavis
Copy link
Contributor

@estebanprimost Now we have a dedicated nvm package. Just omf install nvm. Awesome fish completions included! 🍻

@passcod
Copy link
Contributor

passcod commented Mar 2, 2016

Man, again? I thought they resolved this. The omf project seems to be plagued with copyright problems.

@derekstavis
Copy link
Contributor

Man, again? I thought they resolved this.

We also thought this was solved, but then we got striked again by dirty competition. Github should be freeing our repository in next few days, as the requester gave up on fighting.

The omf project seems to be plagued with copyright problems.

In fact we (omf project) never infringed copyright. But it's how DMCA requests work. You don't need to prove anything and Github takes down your repo to keep safe harbour protection.

@passcod
Copy link
Contributor

passcod commented Mar 2, 2016

Yes, apologies. I really meant to say "DMCA requests" but left it as is because I didn't remember what had happened and left to research it. Then I got bored of reading about douchenozzles, but let's not hijack this thread further.

Outside people looking to use omf: find someone who already has an install and ask them for a tarball or git clone or something. Git is distributed, yay.

@derekstavis
Copy link
Contributor

Sorry if I sounded gross @passcod, I was affected by such a hard time in Oh My Fish. But well.. Now we are back!!

@shangsunset
Copy link

Fish shell noob here. while function nvm bass source ~/.nvm/nvm.sh ';' nvm $argv end makes nvm work in fish, installed node and npm wont work properly until i execute a nvm command. How to make them available on shell startup? Thanks.

@derekstavis
Copy link
Contributor

derekstavis commented Apr 14, 2016

Hey @shangsunset, install nvm wrapper via Oh My Fish and forget about issues. It will also allow you to use completions. Give a look at https://github.com/derekstavis/plugin-nvm

@shangsunset
Copy link

@derekjkeller yea. i was using fisherman at first. ended up switching to oh-my-fish and your plugin-nvm works perfectly :)

@derekstavis
Copy link
Contributor

derekstavis commented Apr 14, 2016

Awesome @shangsunset, I hope you like the plugin. Feel free to file a bug if you find any issue 👍

@ghost
Copy link

ghost commented Apr 16, 2016

Someone reading this thread in the future will be seriously misdirected, so let me fix that.

The reason @shangsunset was having trouble with nvm has nothing to do with fisherman or omf, but incorrect nvm usage.

got bass?

In fish, there are a few ways to run nvm, IMO the best way to go about this is using bass, which lets you run (not just nvm, but also other) non-fish env-altering scripts and have your fish env/vars altered accordingly.

You don't even need fisherman / omf to do any of this.

how??

Create a dummy nvm function (save it to ~/.config/fish/functions/nvm.fish)

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

Run this function at the start of your shell session _every time_ (or when you cd into a directory with a .nvmrc). If you don't do this, you won't be able to run node or npm since they will _not_ be in your $PATH.

okay, but i don't want to run nvm every time

If you don't want to run nvm at the start of the shell / or when cd'ing into a path with .nvmrc, then just add this to your ~/.config/fish/config.fish:

bass source ~/.nvm/nvm.sh --no-use ';' nvm

Related edc/bass#28

@jethrokuan
Copy link

Minor correction: a .nvmrc in the directory does not guarantee that node or npm is added into the path upon entering the directory. nvm use reads from it if no node version is specified in the command.

While it is good that you got it working, knowing what goes on under the hood is also essential in debugging problems you might face in the future.

@derekjkeller
Copy link
Contributor

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

@ghost
Copy link

ghost commented Apr 27, 2016

Hi again and thanks to @ljharb for merging b0693f2.

Running nvm in fish can be laborious, so I wrote an nvm_-like_ node version manager in fish: fin.

@danielb2
Copy link
Contributor

danielb2 commented Jan 27, 2017

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

@eugenet8k
Copy link

NVM has an example of a change directory hook to automatically call nvm use: https://github.com/creationix/nvm#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file

If you want the same in Fish, use this adopted function:
https://gist.github.com/eugenet8k/535bf3c51d1fc7c31cb8784e55d4dae4#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file

@osbre
Copy link

osbre commented Feb 11, 2020

With this package installed, nvm works fine:

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

@elovin
Copy link

elovin commented Nov 18, 2021

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
Copy link
Member

ljharb commented Nov 18, 2021

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

@elovin
Copy link

elovin commented Dec 1, 2021

@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

This comment was marked as spam.

@alaslyalasel

This comment was marked as spam.

@vladimiremi
Copy link

vladimiremi commented Jul 8, 2024

Thanks @Globegitter has worked me too :

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

@calle2010
Copy link

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
Copy link

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

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests