There are several cases:
- RVM not installed
- RVM is installed but not used (i.e. its bindir is added to PATH, but it is not received)
- RVM is installed and used, but not loaded (i.e. it is created, but you check it with a script)
- RVM installed and used
The only way to check all 4 cases is to check environment variables starting with rvm_ :
env | egrep -v '^PATH' | egrep '^rvm_path'
We can check variables like MY_RUBY_HOME or GEM_HOME , but they can be manually reloaded by the user, so we cannot guarantee that we use RVM.
If you intend to use the above command in a script, you can change it as follows and check the exit code:
env | egrep -v '^PATH' | egrep -q '^rvm_path'
Of course, if you just need to find out if there is an RVM on disk and is available, you can go with simpler ones, for example, others offered here.
source share