1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00

Add Scripting With RVM as a ruby til

This commit is contained in:
jbranchaud
2019-02-01 16:01:36 -06:00
parent 3e1f4afb89
commit 4b4e1a6c8b
2 changed files with 39 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
For a steady stream of TILs from a variety of rocketeers, checkout
[til.hashrocket.com](https://til.hashrocket.com/).
_754 TILs and counting..._
_755 TILs and counting..._
---
@@ -622,6 +622,7 @@ _754 TILs and counting..._
- [Returning With Sequel](ruby/returning-with-sequel.md)
- [Running A Single MiniTest Example](ruby/running-a-single-minitest-example.md)
- [Safe Navigation Operator](ruby/safe-navigation-operator.md)
- [Scripting With RVM](ruby/scripting-with-rvm.md)
- [Scroll To Top Of Page With Capybara](ruby/scroll-to-top-of-page-with-capybara.md)
- [Set RVM Default Ruby](ruby/set-rvm-default-ruby.md)
- [Show Public Methods With Pry](ruby/show-public-methods-with-pry.md)

View File

@@ -0,0 +1,37 @@
# Scripting With RVM
Because of how [RVM](https://rvm.io/) works under the hood, you have to do a
couple things to get it to work in a script.
First, you need to ensure that your script is using `bash` instead of `sh`,
so add this to the top of your scripts:
```bash
#!/bin/bash
```
You'll then want to make sure that RVM is sourced. Their
[docs](https://rvm.io/workflow/scripting) recommend sourcing in a script
like this:
```bash
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
fi
```
After that, you can utilize any of the capabilities of RVM in your script as
you'd like.