How to set default Ruby version with RVM?

前端 未结 4 1787
情话喂你
情话喂你 2020-12-04 17:28

Ubuntu 11.

I do the following:

$ rvm --default use 1.9.2 and I get:

Using /home/md/.rvm/gems/ruby-1.9.2-p180 so that is goo

4条回答
  •  误落风尘
    2020-12-04 18:13

    If you put the RVM source line in your bashrc (in order to ensure that non-interactive shells have access to RVM), you will need to source .bashrc from your .bash_profile with the following as the last lines in your .bash_profile

    if [ -f "$HOME/.bashrc" ]; then
      source $HOME/.bashrc
    fi
    

    This pre-supposes that you have

    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
    

    in your $HOME/.bashrc. This is a good way to ensure that both interactive/login and non-interactive shells are able to find and load RVM correctly. Multi-User installs accomplish the same thing via the /etc/profile.d/rvm.sh file.

    After that, you should have no problems defining a default Ruby to use via

    rvm 1.9.2 --default
    

    or

    rvm use 1.9.2@mygemset --default
    

    Its better to define a default gemset to use so as not to pollute your 'default' or 'global' gemsets.

    If you are using non-interactive shells, be aware that they genereally operate in SH-compatibility mode which then requires you to set

    BASH_ENV="$HOME/.bashrc"
    

    in your $HOME/.profile in order you load RVM, or to set that within your script directly. The reason for this is that when bash is operating in SH mode it does not directly load .bash_profile or .bashrc as SH doesn't use those files, and bash is attempting to mimic the loading and execution process of the SH shell.

提交回复
热议问题