RVM (Ruby Version Manager) をインストールしてみました。

複数の Rails 環境を作ってみるのを目標にしてみます。

環境

一般ユーザでインストール

System 全体用にインストールする方法もありますが、 今回は一般ユーザ用にインストールしてみました。

1行実行するだけです。 かなり詳しい案内も表示されます。

#pre{{ iMac:~ sugimura$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed

100 986 100 986 0 0 3494 0 --:--:-- --:--:-- --:--:-- 7042 Cloning into rvm... remote: Counting objects: 16345, done. remote: Compressing objects: 100% (4267/4267), done. remote: Total 16345 (delta 11025), reused 15855 (delta 10649) Receiving objects: 100% (16345/16345), 2.92 MiB | 1.00 MiB/s, done. Resolving deltas: 100% (11025/11025), done.

 RVM:  Shell scripts enabling management of multiple ruby environments.
 RTFM: http://rvm.beginrescueend.com/
 HELP: http://webchat.freenode.net/?channels=rvm (#rvm on irc.freenode.net)

Installing RVM to /Users/sugimura/.rvm/

   Correct permissions for base binaries in /Users/sugimura/.rvm/bin...
   Copying manpages into place.
 Notes for Darwin ( Mac OS X )
   For Snow Leopard be sure to have Xcode Tools Version 3.2.1 (1613) or later
   You should download the latest Xcode tools from developer.apple.com.
     (This is since the dvd install for Snow Leopard contained bugs).
   If you intend on installing MacRuby you must install LLVM first.
   If you intend on installing JRuby you must install the JDK.
   If you intend on installing IronRuby you must install Mono (version 2.6 or greater is recommended).
   To seamlessly abandon the Apple-installed system ruby (ruby 1.8.7 patchlevel 174 for Snow Leopard):
   rvm install 1.8.7 # installs patch 302: closest supported version
   rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system # migrate your gems
   rvm --default 1.8.7
 
 You must now complete the install by loading RVM in new shells.
 1) Place the folowing line at the end of your shell's loading files
    (.bashrc or .bash_profile for bash and .zshrc for zsh),
    after all PATH/variable settings:
    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.
    You only need to add this line the first time you install rvm.
 2) Ensure that there is no 'return' from inside the ~/.bashrc file,
    otherwise rvm may be prevented from working properly.
    
 This means that if you see something like:
   '[ -z "$PS1" ] && return'
 then you change this line to:
 if [[ -n "$PS1" ]] ; then
   # ... original content that was below the '&& return' line ...
 fi # <= be sure to close the if at the end of the .bashrc.
 # This is a good place to source rvm v v v
 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"  # This loads RVM into a shell session.

EOF - This marks the end of the .bashrc file

    Be absolutely *sure* to REMOVE the '&& return'.
    If you wish to DRY up your config you can 'source ~/.bashrc' at the bottom of your .bash_profile.
    Placing all non-interactive (non login) items in the .bashrc,
    including the 'source' line above and any environment settings.
 3) CLOSE THIS SHELL and open a new one in order to use rvm.
 

Installation of RVM to /Users/sugimura/.rvm/ is complete.

sugimura,

Thank you very much for using RVM! I sincerely hope that RVM helps to make your work both easier and more enjoyable.

If you have any questions, issues and/or ideas for improvement please join#rvm on irc.freenode.net and let me know, note you must register (http://bit.ly/5mGjlm) and identify (/msg nickserv <nick> <pass>) to talk, this prevents spambots from ruining our day.

My irc nickname is 'wayneeseguin' and I hang out in #rvm typically

 ~09:00-17:00EDT and again from ~21:00EDT-~23:00EDT

If I do not respond right away, please hang around after asking your question, I will respond as soon as I am back. It is best to talk in

#rvm itself as then other users can help out should I be offline.

Be sure to get head often as rvm development happens fast, you can do this by running 'rvm get head' followed by 'rvm reload' or opening a new shell

 w⦿‿⦿t
   ~ Wayne

iMac:~ sugimura$ }}

インストール後の設定

書いてある通りですが、~/.bash_profile で設定します。

#pre{{ [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session. }}

これで .bash_profile を読み込み直したら、rvm コマンドが使えるようになります。

#pre{{ iMac:~ sugimura$ rvm help

Usage

 rvm [Flags] [Options] Action [Implementation[,Implementation[,...]]

Flags

 --head        - with update, updates rvm to git head version.
 --rubygems    - with update, updates rubygems for selected ruby
 --default     - with 'rvm use X', sets the default ruby for new shells to X.

... }}

Ruby のインストール

RVM 管理にする Ruby は別にインストールする必要があるようです。

管理できる Ruby の一覧はこのように取れます。

#pre{{ iMac:~ sugimura$ rvm list known

# MRI Rubies [ruby-]1.8.6[-p399] [ruby-]1.8.6-head [ruby-]1.8.7[-p302] [ruby-]1.8.7-head [ruby-]1.9.1-p243 [ruby-]1.9.1[-p376] [ruby-]1.9.1-p429 [ruby-]1.9.1-head [ruby-]1.9.2-preview1 [ruby-]1.9.2-preview3 [ruby-]1.9.2-rc1 [ruby-]1.9.2-rc2 [ruby-]1.9.2[-p0] ... }}

インストールされている Ruby は単に list です。

#pre{{ iMac:~ sugimura$ rvm list

rvm rubies

iMac:~ sugimura$ }}

1.9.2 をインストールしてみます。

#pre{{ iMac:~ sugimura$ rvm install ruby-1.9.2 /Users/sugimura/.rvm/rubies/ruby-1.9.2-p0, this may take a while depending on your cpu(s)...

ruby-1.9.2-p0 - #fetching ruby-1.9.2-p0 - #downloading ruby-1.9.2-p0, this may take a while depending on your connection...

 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed

100 8296k 100 8296k 0 0 3156k 0 0:00:02 0:00:02 --:--:-- 3238k ruby-1.9.2-p0 - #extracting ruby-1.9.2-p0 to /Users/sugimura/.rvm/src/ruby-1.9.2-p0 ... Install of ruby-1.9.2-p0 - #complete }}

入ったことを確認してみます。

#pre{{ iMac:~ sugimura$ rvm list

rvm rubies

=> ruby-1.9.2-p0 [ x86_64 ]

iMac:~ sugimura$ }}

使うには rvm use を実行します。

#pre{{ iMac:~ sugimura$ rvm use ruby-1.9.2 Using /Users/sugimura/.rvm/gems/ruby-1.9.2-p0 iMac:~ sugimura$ which ruby /Users/sugimura/.rvm/rubies/ruby-1.9.2-p0/bin/ruby iMac:~ sugimura$ which irb /Users/sugimura/.rvm/rubies/ruby-1.9.2-p0/bin/irb iMac:~ sugimura$ which rake /Users/sugimura/.rvm/gems/ruby-1.9.2-p0/bin/rake }}

OS 標準の 1.8.7 に戻すには rvm use system です。

#pre{{ iMac:~ sugimura$ rvm use system Now using system ruby. iMac:~ sugimura$ which ruby /usr/bin/ruby iMac:~ sugimura$ which irb /usr/bin/irb iMac:~ sugimura$ which rake /usr/bin/rake }}

gem の切り替え

複数の Rails 環境を作るために、 RVM が提供する GemSets で gem を切り替えることができます。

gemset の管理

最初はほとんど空です。

#pre{{ iMac:~ sugimura$ rvm use 1.9.2 Using /Users/sugimura/.rvm/gems/ruby-1.9.2-p0 iMac:~ sugimura$ gem list

LOCAL GEMS ***

rake (0.8.7) iMac:~ sugimura$ rvm gemset list

gemsets for ruby-1.9.2-p0 (found in /Users/sugimura/.rvm/gems/ruby-1.9.2-p0) global

iMac:~ sugimura$ }}

rails2 と rails3 を作ってみます。

#pre{{ iMac:~ sugimura$ rvm gemset create rails2 'rails2' gemset created (/Users/sugimura/.rvm/gems/ruby-1.9.2-p0@rails2). iMac:~ sugimura$ rvm gemset create rails3 'rails3' gemset created (/Users/sugimura/.rvm/gems/ruby-1.9.2-p0@rails3). iMac:~ sugimura$ rvm gemset list

gemsets for ruby-1.9.2-p0 (found in /Users/sugimura/.rvm/gems/ruby-1.9.2-p0) global rails2 rails3

iMac:~ sugimura$ }}

Ruby 1.9.2 + Rails 2.3.8

rails2 の gemset を使う指定をします。

#pre{{ iMac:~ sugimura$ rvm use 1.9.2@rails2 Using /Users/sugimura/.rvm/gems/ruby-1.9.2-p0 with gemset rails2 }}

Rails 2.3.8 をインストールします。

#pre{{ iMac:~ sugimura$ gem install rails -v 2.3.8 Successfully installed activesupport-2.3.8 Successfully installed activerecord-2.3.8 Successfully installed rack-1.1.0 Successfully installed actionpack-2.3.8 Successfully installed actionmailer-2.3.8 Successfully installed activeresource-2.3.8 Successfully installed rails-2.3.8 7 gems installed Installing ri documentation for activesupport-2.3.8... Installing ri documentation for activerecord-2.3.8... ... }}

#pre{{ iMac:~ sugimura$ which rails /Users/sugimura/.rvm/gems/ruby-1.9.2-p0@rails2/bin/rails iMac:~ sugimura$ rails -v Rails 2.3.8 iMac:~ sugimura$ gem list

LOCAL GEMS ***

actionmailer (2.3.8) actionpack (2.3.8) activerecord (2.3.8) activeresource (2.3.8) activesupport (2.3.8) rack (1.1.0) rails (2.3.8) rake (0.8.7) iMac:~ sugimura$ }}

Ruby 1.9.2 + Rails 3.0.3

同様に、Rails 3.0.3 の環境も作ってみます。

#pre{{ iMac:~ sugimura$ rvm use 1.9.2@rails3 Using /Users/sugimura/.rvm/gems/ruby-1.9.2-p0 with gemset rails3 }}

gemset を切り替えたので、先ほどインストールした Rails 2.3.8 はここからは見えません。

#pre{{ iMac:~ sugimura$ gem list

LOCAL GEMS ***

rake (0.8.7) iMac:~ sugimura$ }}

Rails 3.0.3 をインストールします。 現時点 (2011/12/19) では、バージョンを指定しなければ 3.0.3 になります。

#pre{{ iMac:~ sugimura$ gem install rails Successfully installed activesupport-3.0.3 Successfully installed builder-2.1.2 Successfully installed i18n-0.5.0 ... }}

入りました。

#pre{{ iMac:~ sugimura$ which rails /Users/sugimura/.rvm/gems/ruby-1.9.2-p0@rails3/bin/rails iMac:~ sugimura$ rails -v Rails 3.0.3 iMac:~ sugimura$ gem list

LOCAL GEMS ***

abstract (1.0.0) actionmailer (3.0.3) actionpack (3.0.3) activemodel (3.0.3) activerecord (3.0.3) activeresource (3.0.3) activesupport (3.0.3) arel (2.0.6) builder (2.1.2) bundler (1.0.7) erubis (2.6.6) i18n (0.5.0) mail (2.2.12) mime-types (1.16) polyglot (0.3.1) rack (1.2.1) rack-mount (0.6.13) rack-test (0.5.6) rails (3.0.3) railties (3.0.3) rake (0.8.7) thor (0.14.6) treetop (1.4.9) tzinfo (0.3.23) iMac:~ sugimura$ }}

状況を調べる

いま何を使っているのかを知るには、rvm info とします。 出力は適当に改行しています。

#pre{{ iMac:~ sugimura$ rvm info

ruby-1.9.2-p0@rails3:

 system:
   uname:       "Darwin iMac.local 10.5.0 Darwin Kernel Version 10.5.0: Fri Nov
 5 23:19:13 PDT 2010; root:xnu-1504.9.17~1/RELEASE_X86_64 x86_64"
   bash:        "/bin/bash => GNU bash, version 3.2.48(1)-release 

(x86_64-apple-darwin10.0)"

   zsh:         "/bin/zsh => zsh 4.3.9 (i386-apple-darwin10.0)"
 rvm:
   version:      "rvm 1.1.6 by Wayne E. Seguin (wayneeseguin@gmail.com) 

[http://rvm.beginrescueend.com/]"

 ruby:
   interpreter:  "ruby"
   version:      "1.9.2p0"
   date:         "2010-08-18"
   platform:     "x86_64-darwin10.5.0"
   patchlevel:   "2010-08-18 revision 29036"
   full_version: "ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.5.0]"
 homes:
   gem:          "/Users/sugimura/.rvm/gems/ruby-1.9.2-p0@rails3"
   ruby:         "/Users/sugimura/.rvm/rubies/ruby-1.9.2-p0"
 binaries:
   ruby:         "/Users/sugimura/.rvm/rubies/ruby-1.9.2-p0/bin/ruby"
   irb:          "/Users/sugimura/.rvm/rubies/ruby-1.9.2-p0/bin/irb"
   gem:          "/Users/sugimura/.rvm/rubies/ruby-1.9.2-p0/bin/gem"
   rake:         "/Users/sugimura/.rvm/gems/ruby-1.9.2-p0@global/bin/rake"
 environment:
   PATH:         "/Users/sugimura/.rvm/gems/ruby-1.9.2-p0@rails3/bin:

/Users/sugimura/.rvm/gems/ruby-1.9.2-p0@global/bin: /Users/sugimura/.rvm/rubies/ruby-1.9.2-p0/bin: /Users/sugimura/.rvm/bin:/opt/local/bin:/usr/bin: /bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"

   GEM_HOME:     "/Users/sugimura/.rvm/gems/ruby-1.9.2-p0@rails3"
   GEM_PATH:     "/Users/sugimura/.rvm/gems/ruby-1.9.2-p0@rails3:

/Users/sugimura/.rvm/gems/ruby-1.9.2-p0@global"

   MY_RUBY_HOME: "/Users/sugimura/.rvm/rubies/ruby-1.9.2-p0"
   IRBRC:        "/Users/sugimura/.rvm/rubies/ruby-1.9.2-p0/.irbrc"
   RUBYOPT:      ""
   gemset:       "rails3"

iMac:~ sugimura$ }}

参考文献



トップ   差分 履歴 リロード   一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2011-01-29 (土) 15:27:49