3

when you have something like..

given inside projectx an .rvmrc file specifying ruby 1.9.2 and having two rubies on my system (ree-1.8.7 and ruby1.9.2)

#!/bin/bash

cd applications/projectx
which ruby
ruby -v

the last two lines output ree-1.8.7 and its path which was not I intended to use.

poymode
  • 1,479
  • 3
  • 11
  • 14
  • What exactly does the `.rvmrc` file say and what does `rvm list` say? Are you sourcing the RVM scripts in your shell's initialization files? There should be something like `source ~/.rvm/scripts/rvm` in your shell config files. – mu is too short Jun 30 '11 at 04:38

3 Answers3

8

Yes


Rvm does define a wrapper around cd that looks like this:

cd () 
{ 
    builtin cd "$@";
    local result=$?;
    __rvm_project_rvmrc;
    __rvm_after_cd;
    return $result
}

It's difficult to tell why your .rvmrc isn't working. Rvm does support project-specific .rvmrc files, but you didn't post yours.

DigitalRoss
  • 143,651
  • 25
  • 248
  • 329
  • It's possible that the script he is running does not load whatever function definitions are declared by rvm, and so they would not have have the cd replacement. He may need to run __rvm_project_rvmrc and __rvm_after_cd manually. Bash also has an "export -f" capability which is not compatible with other shells, but since his script is #!/bin/bash it may work as well. – cxreg Jun 30 '11 at 04:49
  • Hey thanks for answers. Apparently I solved mine by sourcing by script that will call cd. – poymode Jul 03 '11 at 11:04
3

You need to source rvm inside your script, when you run a script it doesn't load your .bashrc. Simply add a line like

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

to the start of your script.

Nemo157
  • 3,559
  • 19
  • 27
1

If you are using RVM 1.7.0 or later you need to enable project specific .rvmrc files by adding this line to ~/.rvmrc (or system .rvmrc):

rvm_project_rvmrc=1

See: https://rvm.io/workflow/rvmrc/

mpapis
  • 52,729
  • 14
  • 121
  • 158
Slobodan Kovacevic
  • 6,848
  • 3
  • 29
  • 33