1

I have RVM and Ruby installed on OS X. I set the default version using:

rvm use 1.9.3-p194 --default

But this works only for the current terminal session. When I start a new session, ruby -v returns my System's Ruby version.

Any hints?

UPD

macbook:~ mighter$ rvm info

ruby-1.9.3-p194:

  system:
    uname:       "Darwin macbook.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64"
    system:      "osx/10.8/x86_64"
    bash:        "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)"
    zsh:         "/bin/zsh => zsh 4.3.11 (i386-apple-darwin12.0)"

  rvm:
    version:      "rvm 1.18.5 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
    updated:      "1 hour 22 minutes 16 seconds ago"

  ruby:
    interpreter:  "ruby"
    version:      "1.9.3p194"
    date:         "2012-04-20"
    platform:     "x86_64-darwin12.2.0"
    patchlevel:   "2012-04-20 revision 35410"
    full_version: "ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.2.0]"

  homes:
    gem:          "/usr/local/rvm/gems/ruby-1.9.3-p194"
    ruby:         "/usr/local/rvm/rubies/ruby-1.9.3-p194"

  binaries:
    ruby:         "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby"
    irb:          "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/irb"
    gem:          "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/gem"
    rake:         "/usr/local/rvm/gems/ruby-1.9.3-p194@global/bin/rake"

  environment:
    PATH:         "/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin"
    GEM_HOME:     "/usr/local/rvm/gems/ruby-1.9.3-p194"
    GEM_PATH:     "/usr/local/rvm/gems/ruby-1.9.3-p194:/usr/local/rvm/gems/ruby-1.9.3-p194@global"
    MY_RUBY_HOME: "/usr/local/rvm/rubies/ruby-1.9.3-p194"
    IRBRC:        "/usr/local/rvm/rubies/ruby-1.9.3-p194/.irbrc"
    RUBYOPT:      ""
    gemset:       ""

After logging in:

macbook:~ mighter$ rvm info

system:

  system:
    uname:       "Darwin macbook.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64"
    system:      "osx/10.8/x86_64"
    bash:        "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)"
    zsh:         "/bin/zsh => zsh 4.3.11 (i386-apple-darwin12.0)"

  rvm:
    version:      "rvm 1.18.5 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
    updated:      "1 hour 21 minutes 18 seconds ago"

  homes:
    gem:          "not set"
    ruby:         "not set"

  binaries:
    ruby:         "/usr/bin/ruby"
    irb:          "/usr/bin/irb"
    gem:          "/usr/bin/gem"
    rake:         "/usr/bin/rake"

  environment:
    PATH:         "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/usr/local/rvm/bin"
    GEM_HOME:     ""
    GEM_PATH:     ""
    MY_RUBY_HOME: ""
    IRBRC:        ""
    RUBYOPT:      ""
    gemset:       ""

UPD2

macbook:~ mighter$ cat .bashrc 

PATH=$PATH:/usr/local/rvm/bin # Add RVM to PATH for scripting
macbook:~ mighter$ cat .bash_profile 

[[ -s "/usr/local/rvm/scripts/rvm" ]] && source "/usr/local/rvm/scripts/rvm" # Load RVM into a shell session *as a function*

UPD3

/usr/local/rvm/scripts/rvm
#!/usr/bin/env bash

# rvm : Ruby enVironment Manager
# https://rvm.io
# https://github.com/wayneeseguin/rvm

# also duplicated in scripts/base
__rvm_has_opt()
{
  {
    [[ -n "${ZSH_VERSION}"  ]] && setopt | grep "^${1}$" >/dev/null 2>&1
  } ||
  {
    [[ -n "${BASH_VERSION}" ]] && [[ ":$SHELLOPTS:" =~ ":${1}:" ]]
  } ||
  return 1
}

# Do not allow sourcing RVM in `sh` - it's not supported
# return 0 to exit from sourcing this script without breaking sh
if __rvm_has_opt "posix"
then return 0
fi

# TODO: Alter the variable names to make sense
\export HOME rvm_prefix rvm_user_install_flag rvm_path
HOME="${HOME%%+(\/)}" # Remove trailing slashes if they exist on HOME

[[ -n "${rvm_stored_umask:-}" ]] || export rvm_stored_umask=$(umask)
if (( ${rvm_ignore_rvmrc:=0} == 0 ))
then
  rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
  if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
     then rvm_rvmrc_files+=( "${rvm_prefix}/.rvmrc" )
  fi

  for rvmrc in "${rvm_rvmrc_files[@]}"
  do
    if [[ -f "$rvmrc" ]]
    then
      if GREP_OPTIONS="" \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
      then
        printf "%b" "
Error:
        $rvmrc is for rvm settings only.
        rvm CLI may NOT be called from within $rvmrc.
        Skipping the loading of $rvmrc"
        return 1
      else
        source "$rvmrc"
      fi
    fi
  done
  unset rvm_rvmrc_files
fi

# detect rvm_path if not set
if [[ -z "${rvm_path:-}" ]]
then
  if (( UID == 0 ))
  then
    if (( ${rvm_user_install_flag:-0} == 0 ))
    then
      rvm_user_install_flag=0
      rvm_prefix="/usr/local"
      rvm_path="${rvm_prefix}/rvm"
    else
      rvm_user_install_flag=1
      rvm_prefix="$HOME"
      rvm_path="${rvm_prefix}/.rvm"
    fi
  else
    if [[ -d "$HOME/.rvm" && -s "$HOME/.rvm/scripts/rvm" ]]
    then
      rvm_user_install_flag=1
      rvm_prefix="$HOME"
      rvm_path="${rvm_prefix}/.rvm"
    else
      rvm_user_install_flag=0
      rvm_prefix="/usr/local"
      rvm_path="${rvm_prefix}/rvm"
    fi
  fi
else
  # remove trailing slashes, btw. %%/ <- does not work as expected
  rvm_path="${rvm_path%%+(\/)}"
fi

# guess rvm_prefix if not set
if [[ -z "${rvm_prefix}" ]]
then
  rvm_prefix=$( dirname $rvm_path )
fi

# guess rvm_user_install_flag if not set
if [[ -z "${rvm_user_install_flag}" ]]
then
  if [[ "${rvm_prefix}" == "${HOME}" ]]
  then
    rvm_user_install_flag=1
  else
    rvm_user_install_flag=0
  fi
fi

export rvm_loaded_flag
if [[ -n "${BASH_VERSION:-}" || -n "${ZSH_VERSION:-}" ]] &&
  typeset -f rvm >/dev/null 2>&1
then
  rvm_loaded_flag=1
else
  rvm_loaded_flag=0
fi

if (( ${rvm_loaded_flag:=0} == 0 )) || (( ${rvm_reload_flag:=0} == 1 ))
then
  if [[ -n "${rvm_path}" && -d "$rvm_path" ]]
  then
    true ${rvm_scripts_path:="$rvm_path/scripts"}

    if [[ -f "$rvm_scripts_path/base" ]]
    then
      source "$rvm_scripts_path/base"
    else
      printf "%b" "WARNING:
      Could not source '$rvm_scripts_path/base' as file does not exist.
      RVM will likely not work as expected.\n"
    fi

    __rvm_ensure_is_a_function
    __rvm_setup

    export rvm_version
    rvm_version="$(cat "$rvm_path/VERSION") ($(cat "$rvm_path/RELEASE" 2>/dev/null))"

    alias rvm-restart="rvm_reload_flag=1 source '${rvm_scripts_path:-${rvm_path}/scripts}/rvm'"

    if ! builtin command -v ruby >/dev/null 2>&1 ||
      builtin command -v ruby | GREP_OPTIONS="" \grep -v "${rvm_path}" >/dev/null ||
      builtin command -v ruby | GREP_OPTIONS="" \grep "${rvm_path}/bin/ruby$" >/dev/null
    then
      if [[ -s "$rvm_environments_path/default" && "${rvm_action}" != "switch" ]]
      then
        source "$rvm_environments_path/default"
      elif [[ -s "$rvm_path/environments/default" ]]
      then
        source "$rvm_path/environments/default"
      fi
    fi

    # Makes sure rvm_bin_path is in PATH atleast once.
    __rvm_conditionally_add_bin_path

    if (( ${rvm_reload_flag:=0} == 1 ))
    then
      [[ "${rvm_auto_reload_flag:-0}" == 2 ]] || printf "%b" 'RVM reloaded!\n'
      # make sure we clean env on reload
      __rvm_env_loaded=1
      unset __rvm_project_rvmrc_lock
    fi

    rvm_loaded_flag=1
  else
    printf "%b" "\n\$rvm_path ($rvm_path) does not exist."
  fi
  unset rvm_prefix_needs_trailing_slash rvm_gems_cache_path \
    rvm_gems_path rvm_project_rvmrc_default rvm_gemset_separator rvm_reload_flag
else
  source "${rvm_scripts_path:="$rvm_path/scripts"}/initialize"
  __rvm_setup
fi

if [[ -t 0 && ${rvm_project_rvmrc:-1} -gt 0 ]] &&
  rvm_is_a_shell_function no_warning &&
  ! __function_on_stack __rvm_project_rvmrc &&
  typeset -f __rvm_project_rvmrc >/dev/null 2>&1
then
  # Reload the rvmrc, use promptless ensuring shell processes does not
  # prompt if .rvmrc trust value is not stored.
  rvm_promptless=1 __rvm_project_rvmrc
  rvm_hook=after_cd
  source "${rvm_scripts_path:-${rvm_path}/scripts}/hook"
fi

__rvm_teardown
  • What's the output of rvm list when you open a new shell? Also, take a look here: http://stackoverflow.com/questions/5604877/why-doesnt-rvm-default-work-for-me-on-macosx – Paul Kehrer Feb 03 '13 at 21:47
  • Not really an answer, but I began having the same exact problem and decided to use that time to switch over to [rbenv](https://github.com/sstephenson/rbenv/). Haven't looked back since. – Marc Baumbach Feb 03 '13 at 21:48
  • Please append the output of `rvm info` to your question. – the Tin Man Feb 03 '13 at 21:51
  • @theTinMan please take a look at update –  Feb 03 '13 at 22:19
  • @tadman's answer is on the right track. – the Tin Man Feb 03 '13 at 22:21
  • @theTinMan I see, but I have no luck. Again, should manual execution of script do the job? If so, I guess there's something wrong with the script, because I try to execute it after logging in and again I have System's ruby, not the one I wanted to use. –  Feb 03 '13 at 22:24
  • Please append the output of `grep source ~/.bash_profile ~/.bashrc` to the question. – the Tin Man Feb 03 '13 at 22:30
  • @theTinMan yeah...it was pointing not to the root installation, but to the local installation. I've changed it(see UPD2), but this also does nothing. –  Feb 03 '13 at 22:37
  • @theTinMan please take a look at script, because it is executed on login, but obviously it is broken. –  Feb 04 '13 at 06:50
  • I don't maintain RVM. If you feel the script is broken, I'd recommend discussing it with the developers. You'll find they are very responsive. See "[Help & Support](https://rvm.io/support/)" for the information needed to contact them. Before doing so, remember that the script in question is used, as is, by everyone else using RVM, without problem, so odds are very good the script is fine. – the Tin Man Feb 04 '13 at 14:45

1 Answers1

3

You're probably not including the rvm script in your profile. If you have a previous installation of rvm it might be loading the wrong files, the location of them has shifted slightly but in important ways from historical versions.

The installation documentation recommends:

echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile

Of course if you're not using bash or your .bash_profile is not being loaded for some reason, this could be the cause of your problem.

If you've done a root install of rvm then you'll need to adjust that line to include /usr/local/scripts/rvm, or wherever it installed, and alter /etc/bash_profile instead.

tadman
  • 208,517
  • 23
  • 234
  • 262
  • I tried sourcing script in /etc/profile, but this has no effect. And if I execute script manually after bash login, should rvm settings be loaded? Because manual execution does nothing. –  Feb 03 '13 at 22:15
  • Please, take a look at UPD3. –  Feb 04 '13 at 06:50
  • This could be a bug in RVM, in which case you might want to report it. – tadman Feb 04 '13 at 14:56