If you type the command in console, it works.
But if you put them in a bash script, problem comes.
#!/bin/bash
rvm use 1.8.7
rvm list # This shows the ruby used in parent shell's rvm.
If you type the command in console, it works.
But if you put them in a bash script, problem comes.
#!/bin/bash
rvm use 1.8.7
rvm list # This shows the ruby used in parent shell's rvm.
From the rvm documentation, it sets up the current shell. When you execute a shell script, you are executing a new shell process. That new process dies when the script ends, so the updates made by
rvm
to your environment disappear.To script this, you'll need to do something more like this:
This will (hopefully) drop you into a shell process with the updated environment provided by
rvm
, and when you are finished, you can justexit
from it to go back to your default environment.Alternatively, you count set up an alias that will modify your current shell environment:
Add that line to your
.bashrc
or.profile
to have it stick around permanently. Any time you want to use1.8.7
, typer187
. You can set up other ones for different versions too, if you like.In the script you are most likely not loading rvm as a function.
http://rvm.io/rvm/basics/
Try to run
echo -n START; rvm use 1.8.7 ; rvm list; echo -n END
without theeval
, and see what it outputs. Everything between START and END will be executed as a command.The shell functions installed by RVM aren't necessarily exported to subshells. In your shell script, you can re-initialize RVM with something like the same command line that's in your .bash_profile or .bashrc:
After you do that, the rvm functions will be available within the shell script.
You do not need the
eval
, and if you still want it, you are using it incorrectly. I would recommend this:But if you really want the
eval
, go with this: