1

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?

mcallan83
  • 96
  • 5

3 Answers3

1

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
Marc Young
  • 3,854
  • 3
  • 18
  • 22
0

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
Noproblem
  • 745
  • 1
  • 6
  • 15
  • I was hoping to avoid adding anything to .bashrc at this point. Basically this script runs before I have my bash\zsh environment setup. Later on in my script, I clone my dotfiles from a git repo and put them in their proper place, where the path to RVM is added. I was hoping by sourcing the RVM script in my bash install script, I could get by without touching the .bashrc, but maybe I need to rethink how I go about this. – mcallan83 Oct 27 '15 at 21:56
  • You could try export rvm for example : export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/sbin:/usr/sbin[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function – Noproblem Oct 28 '15 at 06:18
0

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.

Community
  • 1
  • 1
mcallan83
  • 96
  • 5