How to set default Ruby version with RVM?

前端 未结 4 1767
情话喂你
情话喂你 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.

    0 讨论(0)
  • 2020-12-04 18:24

    do an "rvm list" to see which Ruby versions you have installed.

    then do this if you want to change the version only in one terminal session:

    rvm use 1.8.7
    

    if you want to select the default version for this user account, do this:

    rvm use --default 1.9.2
    

    See:

    rvm use --help
    

    See also this RailsCast:

    http://railscasts.com/episodes/200-rails-3-beta-and-rvm

    http://beginrescueend.com/

    0 讨论(0)
  • 2020-12-04 18:24

    Late to party - anyway.

    You did correctly set the default ruby version: rvm --default use 1.9.2

    However, you need to update your Gemfile to the target ruby, because RVM references that file to select the working ruby version when you open terminal , that's why it reverted to the previous ruby version.

    0 讨论(0)
  • 2020-12-04 18:24

    To Change the Default Version of ruby:

    In Ubuntu

    Go to default Terminal of Ubuntu and then follow the instructions:

    1) Edit -> Profile Preferences
    2) Select "Title and Command"
    3) check "Run command as a login shell"
    4) restart terminal
    

    And after that run this command:

    rvm --default use 2.2.4@gemset_name

    0 讨论(0)
提交回复
热议问题