Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't RVM work in a bash script like it works in an interactive shell?

Tags:

bash

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.
like image 936
Cheng Avatar asked Mar 18 '11 13:03

Cheng


1 Answers

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:

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

After you do that, the rvm functions will be available within the shell script.

like image 93
Brett Avatar answered Nov 15 '22 07:11

Brett