RVM - Multiple versions of Ruby, Rails gemsets


- RVM allows to install multiple versions of ruby/rails/gems and switch between them.
- RVM installs ruby/gem/rails/command tools under $HOME/.rvm/.
- RVM intercepts shell commands and "redirects" commands/uses gems from chosen Ruby/Gemset Rails.
- Rails is installed as a "gemset" under Ruby: e.g. ruby_version@rails_version => ruby-1.9.2-p290@rails-3.2.11.
- Don't use "sudo" for commands (say "gem") under RVM.

RVM - Install desired Ruby and Rails:

# Install RVM

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm requirements

# Install Ruby under RVM

rvm install 1.9.2-p290  # ruby_version
rvm list
//     rvm rubies
//     =* ruby-1.9.2-p290 [ x86_64 ]
rvm use 1.9.2-p290 # ruby_version
//     Using $HOME/.rvm/gems/ruby-1.9.2-p290

# Create gemset under it for installing Rails

rvm gemset create rails-3.2.11 # gemset_name
//     ruby-1.9.2-p290 - #gemset created $HOME/.rvm/gems/ruby-1.9.2-p290@rails-3.2.11
//     ruby-1.9.2-p290 - #generating rails-3.2.11 wrappers........
rvm gemset list
//     gemsets for ruby-1.9.2-p290 (found in $HOME/.rvm/gems/ruby-1.9.2-p290)
//     => (default)
//        global
//        rails-3.2.11
rvm gemset use rails-3.2.11
//     Using ruby-1.9.2-p290 with gemset rails-3.2.11
rvm gemset list
//     gemsets for ruby-1.9.2-p290 (found in $HOME/.rvm/gems/ruby-1.9.2-p290)
//        (default)
//        global
//     => rails-3.2.11
rvm ruby-1.9.2-p290@rails-3.2.11 #ruby_version@gemset_name
//     Using $HOME/.rvm/gems/ruby-1.9.2-p290 with gemset rails-3.2.11

# Repeat following until all errors are gone!

gem install rails -v 3.2.11 # rails_version

# Errors/Solutions:

//     Fetching: rack-cache-1.7.0.gem (100%)
//     ERROR: Error installing rails: rack-cache requires Ruby version >= 1.9.3.
# Find the needed/working gem version number from pre-installed/heroku "gem list".
gem install rack-cache -v 1.2 # as used in our saasbook
gem install i18n -v 0.6.1
bundle install
//     pg 0.18.0 - Error pg_config, libpq-fe.h missing
sudo apt-get install libpq-dev

### Use RVM:

# Load RVM and set/check desired gemsets:
source $HOME/.rvm/scripts/rvm;

# Choose Ruby/Rails gem combo to use:

rvm ruby-1.9.2-p290@rails-3.2.11;
rvm gemset list;

### Install heroku-CLI & pull (usual way!)

sudo add-apt-repository "deb https://cli-assets.heroku.com/branches/stable/apt ./"
curl -L https://cli-assets.heroku.com/apt/release.key | sudo apt-key add -
sudo apt-get install heroku
heroku git:clone -app railsapp

### Build/Run app (usual way!):

cd railsapp
bundle install
rake db:migrate
rake db:seed
rails server

/** Not tried; Not needed?
If you want to setup your rails app to utilize the RVM gemset 2.2.1@rails_2_1_1, similar to the RVM command below...
rvm use ruby-1.9.2-p290@rails-3.2.11
In your Gemfile, specify right below the source line the following two commented lines:
    source 'https://rubygems.org'

### Other alternative:
# In app directory:
gemset ruby-1.9.2-p290@rails-3.2.11
## $ echo "ruby-1.9.2-p290" > .ruby-version
## $ echo "rails-3.2.11" > .ruby-gemset

No comments:

Post a Comment