Cygwin - RVM 環境構築!


今日は、複数の Ruby 環境を簡単に切り替えて使用可能にする環境 RVM(Ruby Version Manager) を Cygwin に構築してみました。

Cygwin に Gem パッケージ RVM をインストールするには、

  • 公式サイトで配布されている tarball からのインストール
  • GitHub からのインストール
  • Gem でのインストール


当方の Cygwin には既に Ruby 1.9.2 がインストールされていますので、「Gem でのインストール」をしてみました。


RVM 環境構築記録



  • Windows XP SP3 (32bit) 上に導入した Cygwin 1.7.9 で作業。
  • Cygwin 上に Ruby 1.9.2 p290 がインストール済み。
  • インストール済み Gem のバージョンは 1.8.13 である。


Cygwin 上で作業するにあたり、予め Cygwin の setup.exe により、以下のパッケージをインストールしておく。 ※ご使用の環境によっては、以下以外のパッケージが必要になるかもしれません。

  • curl
  • ncurses

2.Gem パッケージ RVM のインストール

Gem で RVM パッケージをインストールします。

$ gem install rvm
Fetching: rvm-1.9.2.gem (100%)

  This gem contains only the Ruby libraries for the RVM Ruby API.

  In order to install RVM please use one of the methods listed in the

  such as,

    bash <
  followed by placing the sourcing line in your ~/.bash_profile or wherever may
  be appropriate for your setup (example, .zshenv, /etc/profile, ...):

    # Load RVM into a shell session *as a function*
    [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"

  After completing setup please open a new shell to use RVM and be sure to run
  'rvm notes' to gain a list of dependencies to install before installing the
  first Ruby. You can read more details about this process on the above
  mentioned install page as well as the basics page:



Successfully installed rvm-1.9.2
1 gem installed
Installing ri documentation for rvm-1.9.2...
Installing RDoc documentation for rvm-1.9.2...


$ gem list

*** LOCAL GEMS ***

minitest (1.6.0)
mysql2 (0.3.11)
rake (0.8.7)
rdoc (2.5.8)
rubygems-update (1.8.13)
rvm (1.9.2)


3.RVM のインストール

以下のようにして、RVM をインストールします。

$ bash < <(curl -s -B
Downloading RVM from wayneeseguin branch master
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   125  100   125    0     0     43      0  0:00:02  0:00:02 --:--:--   183
100  792k  100  792k    0     0  45947      0  0:00:17  0:00:17 --:--:--  103k

  RVM:  Shell scripts enabling management of multiple ruby environments.
  HELP: (#rvm on

Installing RVM to /home/masaru/.rvm/
    Correct permissions for base binaries in /home/masaru/.rvm/bin...
    Copying manpages into place.
    Recording config files for rubies.


If you have any questions, issues and/or ideas for improvement please
fork the project and issue a pull request.

If you wish to disable the project .rvmrc file functionality, set
rvm_project_rvmrc=0 in either /etc/rvmrc or ~/.rvmrc.

NOTE: To Multi-User installers, please do NOT forget to add your users to the 'rvm' group.
  The installer no longer auto-adds root or users to the rvm group. Admins must do this.
  Also, please note that group memberships are ONLY evaluated at login time.
  This means that users must log out then back in before group membership takes effect!

Thank you for using RVM!

I sincerely hope that RVM helps to make your life easier and more enjoyable!!!



If you do not wish to enable reading of per-project .rvmrc files, simply set:
        export rvm_project_rvmrc=0
within either your /etc/rvmrc or $HOME/.rvmrc file, then log out and back in.

In case your shell exits on entering directory with freshly checked out sources
you should update .rvmrc file, and replace any `exit ` with `return `.

You _must_ read 'rvm requirements' for additional OS specific requirements for
various rubies, and native-extension gems. Expect failures until those are met!

For screen users, please do not forget to read
You will need to add 'shell -/bin/bash' to your $HOME/.screenrc to properly load RVM.

  You must now complete the install by loading RVM in new shells.

  If you wish to use RVM in an interactive fashion in your shells then
  Place the following 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/masaru/.rvm/scripts/rvm" ]] && source "/home/masaru/.rvm/scripts/rvm"  # This loads RVM into a shell session.

  You only need to add this line the first time you install RVM.

  If you are choosing to source RVM into your environment to switch current
  shell environments, be sure to close this shell and open a new one so that
  the RVM functions load.

Installation of RVM to /home/masaru/.rvm/ is complete.

【2012.07.07 追記 ===>】 Ruby 1.9.3-p194, RVM(RubyGems), RVM 1.14.5 では上記のコマンドでは失敗します。 以下のコマンドで成功しました。

$ bash -s stable < <(curl -s )


$ curl -L | bash -s stable


$ source ~/.rvm/scripts/rvm
$ type rvm | head -n 1
rvm is a function


$ rvm requirements

※詳細はこちら ===> RVM: Ruby Version Manager - Installing RVM 【<==== 2012.07.07 追記】</pre>


RVM のインストールを有効にするためにシェルの有効化を実行します。

$ source ~/.bashrc

5.RVM のインストール確認

RVM がインストールされたか確認してみます。

$ rvm -v

rvm 1.10.0 by Wayne E. Seguin , Michal Papis  []


$ rvm help
= rvm



RVM is the Ruby enVironment Manager (rvm).
It manages Ruby application environments and switching between them.

== Usage

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

== Flags

  --default     - with 'rvm use X', sets the default ruby for new shells to X.
  --debug       - Toggle debug mode on for very verbose output.
  --trace       - Toggle trace mode on to see EVERYTHING rvm is doing.
  --force       - Force install, removes old install & source before install.
  --summary     - Used with rubydo to print out a summary of the commands run.
  --latest      - with gemset --dump skips version strings for latest gem.
  --gems        - with uninstall/remove removes gems with the interpreter.
  --docs        - with install, attempt to generate ri after installation.
  --reconfigure - Force ./configure on install even if Makefile already exists.

== Options

  -v|--version    - Emit rvm version loaded for current shell
  -l|--level      - patch level to use with rvm use / install
     --bin        - path for binaries to be placed (~/.rvm/bin/)
  -S              - Specify a script file to attempt to load and run (rubydo)
  -e              - Execute code from the command line.
  --gems          - Used to set the 'gems_flag', use with 'remove' to remove gems
  --archive       - Used to set the 'archive_flag', use with 'remove' to remove archive
  --patch         - With MRI Rubies you may specify one or more full paths to patches
                    for multiple, specify comma separated:
                    --patch /.../.../a.patch[%prefix],/.../.../.../b.patch
                    'prefix' is an optional argument, which will be bypassed
                    to the '-p' argument of the 'patch' command. It is separated
                    from patch file name with '%' symbol.
  -C|--configure  - custom configure options. If you need to pass several configure
                    options then append them comma separated: -C --...,--...,--...
  --nice          - process niceness (for slow computers, default 0)
  --ree-options   - Options passed directly to ree's './installer' on the command line.
  --with-rubies   - Specifies a string for rvm to attempt to expand for set operations.

== Action

  (Note that for most actions, 'rvm help action-name' may provide more information.)

  * usage    - show this usage information
  version    - show the rvm version installed in rvm_path
  use        - setup current shell to use a specific ruby version
  reload     - reload rvm source itself (useful after changing rvm source)
  implode    - (seppuku) removes the rvm installation completely.
               This means everything in $rvm_path (~/.rvm || /usr/local/rvm).
               This does not touch your profiles. However, this means that you
               must manually clean up your profiles and remove the lines which source RVM.
  get        - {head,latest} upgrades rvm to latest head or release version.
               (If you experience bugs try this first with head version, then
                ask for help in #rvm on and hang around)
  reset      - remove current and stored default & system settings.
               (If you experience odd behavior try this second)
  info       - show the *current* environment information for current ruby
  current    - print the *current* ruby version and the name of any gemset being used.
  debug      - show info plus additional information for common issues

  install    - install one or many ruby versions
               See also:
  uninstall  - uninstall one or many ruby versions, leaves their sources
  remove     - uninstall one or many ruby versions and remove their sources

  migrate    - Lets you migrate all gemsets from one ruby to another.
  upgrade    - Lets you upgrade from one version of a ruby to another, including
               migrating your gemsets semi-automatically.

  wrapper    - generates a set of wrapper executables for a given ruby with the
               specified ruby and gemset combination. Used under the hood for
               passenger support and the like.

  cleanup    - Lets you remove stale source folders / archives and other miscellaneous
               data associated with rvm.
  repair     - Lets you repair parts of your environment e.g. wrappers, env files and
               and similar files (e.g. general maintenance).
  snapshot   - Lets your backup / restore an rvm installation in a lightweight manner.

  disk-usage - Tells you how much disk space rvm install is using.
  tools      - Provides general information about the ruby environment,
               primarily useful when scripting rvm.
  docs       - Tools to make installing ri and rdoc documentation easier.
  rvmrc      - Tools related to managing rvmrc trust and loading.

  do         - runs an arbitrary command against specified and/or all rubies
  tests      - runs 'rake test' across selected ruby versions
  specs      - runs 'rake spec' across selected ruby versions
  monitor    - Monitor cwd for testing, run `rake {spec,test}` on changes.

  gemset     - gemsets:

  rubygems   - Switches the installed version of rubygems for the current ruby.

  gemdir     - display the path to the current gem directory (GEM_HOME).
  srcdir     - display the path to rvm source directory (may be yanked)

  fetch      - Performs an archive / src fetch only of the selected ruby.
  list       - show currently installed rubies, interactive output.
  pkg        - Install a dependency package {readline,iconv,zlib,openssl}
  notes      - Display notes, with operating system specifics.

  export     - Temporarily set an environment variable in the current shell.
  unexport   - Undo changes made to the environment by 'rvm export'.
  requirements - Shows additional OS specific dependencies/requirementes for building various rubies.

== Implementation

  * ruby    - MRI/YARV Ruby (The Gold Standard) {1.8.6,1.8.7,1.9.1,1.9.2...}
  jruby     - JRuby, Ruby interpreter on the Java Virtual Machine.
  rbx       - Rubinius
  ree       - Ruby Enterprise Edition, MRI Ruby with several custom
              patches for performance, stability, and memory.
  macruby   - MacRuby, insanely fast, can make real apps (Mac OS X Only).
  maglev    - GemStone Ruby, awesome persistent ruby object store.
  ironruby  - IronRuby, NOT supported yet. Looking for volunteers to help.
  system    - use the system ruby (eg. pre-rvm state)
  default   - use rvm set default ruby and system if it hasn't been set.

== Resources:

== Contributions:

  Any and all contributions offered in any form, past present or future, to the
  RVM project are understood to be in complete agreement and acceptance with the
  Apache Licence v2.0.



or just use:

    bash <

Copyright (c) 2009-2011 Wayne E. Seguin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
Commands available with 'rvm help':

    alias benchmark build cleanup current debug disk-usage do docs fetch gemdir gemset get implode info install list migrate monitor notes pkg rake remove repair reset ruby rubygems rvmrc snapshot specs srcdir tests tools uninstall update upgrade use wrapper
For additional information please visit RVM's documentation website:
If you still cannot find what an answer to your question, find me 'wayneeseguin' in #rvm on


RVM が正常に動作するか確認します。 まず、RVM でインストールできる Ruby の一覧を表示してみます。

$ rvm list known
# MRI Rubies

# GoRuby

# JRuby

# Rubinius

# Ruby Enterprise Edition

# Kiji

# MagLev

# Mac OS X Snow Leopard Only

# IronRuby -- Not implemented yet.

今の時点では、まだ RVM でインストールされたものはありません。

$ rvm list

rvm rubies

RVM で Ruby 1.9.3 p-0 をインストールしてみます。

$ rvm install 1.9.3
Installing Ruby from source to: /home/masaru/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)...

ruby-1.9.3-p0 - #fetching
ruby-1.9.3-p0 - #downloading ruby-1.9.3-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 9330k  100 9330k    0     0   360k      0  0:00:25  0:00:25 --:--:--  380k
ruby-1.9.3-p0 - #extracting ruby-1.9.3-p0 to /home/masaru/.rvm/src/ruby-1.9.3-p0
ruby-1.9.3-p0 - #extracted to /home/masaru/.rvm/src/ruby-1.9.3-p0
Fetching yaml-0.1.4.tar.gz to /home/masaru/.rvm/archives
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  460k  100  460k    0     0  96082      0  0:00:04  0:00:04 --:--:--  118k
Extracting yaml-0.1.4.tar.gz to /home/masaru/.rvm/src
Configuring yaml in /home/masaru/.rvm/src/yaml-0.1.4.
Compiling yaml in /home/masaru/.rvm/src/yaml-0.1.4.
Installing yaml to /home/masaru/.rvm/usr
ruby-1.9.3-p0 - #configuring
ruby-1.9.3-p0 - #compiling
ruby-1.9.3-p0 - #installing
Retrieving rubygems-1.8.10
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  243k  100  243k    0     0   141k      0  0:00:01  0:00:01 --:--:--  361k
Extracting rubygems-1.8.10 ...
Removing old Rubygems files...
Installing rubygems-1.8.10 for ruby-1.9.3-p0 ...
Installation of rubygems completed successfully.
ruby-1.9.3-p0 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.3-p0 - #importing default gemsets (/home/masaru/.rvm/gemsets/)
Install of ruby-1.9.3-p0 - #complete


$ rvm list

rvm rubies

   ruby-1.9.3-p0 [ i386 ]

RVM で「Ruby 1.9.3 p-0」のインストールはできたが、有効なのはまだ元からインストールされている「Ruby 1.9.2 p290」です。

$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i386-cygwin]

RVM でインストールした「Ruby 1.9.3 p-0」に変更してみます。

$ rvm use 1.9.3
Using /home/masaru/.rvm/gems/ruby-1.9.3-p0
$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [i386-cygwin]

元からインストールされている Ruby に戻してみます。

$ rvm use system
Now using system ruby.
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i386-cygwin]


よく使う RVM のコマンドです。

$ rvm list known   # インストール可能な Ruby リスト表示
$ rvm list         # インストール済みの Ruby リスト表示
$ rvm use 1.9.3    # 1.9.3の環境へ切り替え
$ rvm use system   # システム側の Ruby へ切り替え
$ rvm remove 1.9.3 # 1.9.3のアンインストール




Sponsored Link