How to Make Fish Shell Use an Rvm Ruby by Default

How to make fish shell use an rvm ruby by default

Firstly install rvm fish functions from rvm.io

curl -L --create-dirs -o ~/.config/fish/functions/rvm.fish https://raw.github.com/lunks/fish-nuggets/master/functions/rvm.fish

You should now be able to use rvm command in fish after reopening terminal.

Run the following to add the line rvm default to your fish config file.

echo 'rvm default' >> ~/.config/fish/config.fish

You should now be able to use ruby related binaries and gems after reopening terminal.

RVM is not setting my PATH in `fish`, but should be

Some kind of solution

So far I have it barely working by making the change from:

grep -E '^rvm|^GEM_PATH|^GEM_HOME'

to:

grep -E '^rvm|^[^=]*PATH|^GEM_HOME'

Not sure what side effects that will cause, but from looking at the rvm.fish code, that would seem to be missing.

Related aside

An older version had the ^[^=]*PATH\ term in it, like my system's previous version, and can also be randomly found here: GitHub Gist - ToniRib/rvm.fish
That is for escaping the pipe (|) characters, but I can't see why that is needed inside of single quotes. My fix works specifically without the backslashes, and just plain pipe characters.

Non-functional alternative

I have alternatively tried a patch without the other code such as this one:

and set -xg GEM_PATH (echo $GEM_PATH | sed 's/ /:/g')
and set -xg PATH (echo $GEM_PATH | sed 's/:/ /g') $MY_RUBY_HOME/bin $PATH

I am continuing to add lines to it, but still see various errors. First I needed the "rubies" directory for the correct version of ruby, then both gem paths modified with spaces for fish, and still I am having issues, so taking bash's PATH environment variable wholesale and letting the rvm script do its own work is the best I have so far.

system(rvm 2.5.3 do ruby -v) leads to Warning! PATH is not properly set up

Solution was to add set -gx PATH $HOME/.rvm/bin $PATH to my ~/.config/fish/config.fish.

Hope it helps others.

RVM is not a function, selecting rubies with 'rvm use ...' will not work

Your console is not running as a login shell and hence have no access to rvm function. If you are running Ubuntu, you can:

  1. Open console
  2. Select Edit -> Profile Preferences
  3. Select tab: Title and Command
  4. Check box 'Run command as a login shell'
  5. Restart terminal

How can I use rvm within a Makefile?

When you call RVM from cron (or a Makefile, I would expect) it's important to set up the right environment. The Scout team have a great blog article explaining this:

http://blog.scoutapp.com/articles/2010/09/07/rvm-and-cron-in-production

The important part is ensuring you have a full login shell so you have access to RVM.

/bin/bash -l -c 'the_command_inside_makefile"

To use bash --login by default with capistrano 3 + sshkit + rvm

you can not use rvm use from scripts - unless you source rvm first like you did with the prefix,

but you can use rvm ... do ... in scripts without sourcing:

execute :rvm, "#{ Configs.rvm.ruby }@#{ Configs.rvm.gemset }", "--create", :do, :true


Related Topics



Leave a reply



Submit