Install gem as user on OSX 10.10 Yosemite

Use case : install a specific version of capistrano to deploy stuff somewhere

Let’s say you need to install capistrano 2.* to be able to use your deploy scripts. In this case, I’m running a fresh Yosemite install.

Let’s say we’ll need to setup a specific ruby version with a specific gem version. To do that, we use homebrew and rbenv.

Install homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Follow instructions and refer to homebrew website for more details.

Install rbenv

brew install rbenv ruby-build

Update your shell setup to use rbenv when you open a new terminal

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile

Refresh your current session

source ~/.bash_profile

List available ruby versions

rbenv install -l

Install a specific version of ruby

rbenv install 2.1.5
rbenv global 2.1.5

Check your ruby version

ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin14.0]

Install your gem

gem install capistrano -v "=2.15.5"

You’re done!

cap --version
Capistrano v2.15.5