mcallan83
mcallan83

Reputation: 96

Installing RVM and gems on OSX from a single shell script

I am attempting to install RVM and a few gems from a single bash script that I use to bootstrap a new development box. My goal is to have a single script I can run on a clean install of OSX to install any and everything I use for development.

After installing RVM, I am sourcing the $HOME/.rvm/scripts/rvm script, however in the next line, when I attempt to install a specific version of ruby, it says rvm is not found. Here is my script.

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable --autolibs=homebrew

source "$HOME/.rvm/scripts/rvm"

rvm install 2.1.1
rvm use 2.1.1

gem install jekyll
gem install tmuxinator
gem install scss-lint

I can't understand why this isn't working, because if I run each command individually in the terminal, everything works great.

Any ideas on a 1 script solution to install RVM, a specific version of Ruby, and a few gems?

Upvotes: 1

Views: 812

Answers (3)

mcallan83
mcallan83

Reputation: 96

I found a solution after reading through another stack overflow post.

A comment to one of the answers suggested makeing sure the script runs with bash and not sh. That was my problem. After changing the top line of my script (which wasn't included in my example) from #!/bin/sh to #!/usr/bin/env bash, everything worked as expected.

Upvotes: 0

Marc Young
Marc Young

Reputation: 4012

If you look in .bashrc after RVM they have:

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

What I would do overall for cleanliness

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable --autolibs=homebrew

if [[ -s "$HOME/.rvm/scripts/rvm" ]]; then
  . "$HOME/.rvm/scripts/rvm"
else
  echo "$HOME/.rvm/scripts/rvm" could not be found.
  exit 1
fi

export PATH="$PATH:$HOME/.rvm/bin"
rvm use 2.1.1 --default --install
for i in jekyll tmuxinator scss-lint; do gem install $i; done

Upvotes: 1

Noproblem
Noproblem

Reputation: 775

You may need to add "source ~/.rvm/scripts/rvm" to your ~/.bash_profile file.

echo "source $HOME/.rvm/scripts/rvm" >> ~/.bashrc

To install rvm:

rm -rf ~/.rvm
curl -L https://get.rvm.io | bash -s stable

In your script type:

type_rvm=$(type rvm | head -n 1)
echo "type rmv: $type_rvm"

You could try export rvm:

export PATH=$PATH:/opt/rvm/bin:/opt/rvm/sbin

Upvotes: 0

Related Questions