はじめに

rvmコマンドについてよく忘れるのでメモする。

気づいたこと

  • rvm は、デフォルトでOpenSSLとリンクしない。 rvm reinstall ruby-3.1.0 --with-openssl で、opensslと一緒にビルドできる(manにない…)。

  • ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION' で、rubyがopensslを利用可能な状態かわかる。

RVM コマンド チートシート

1. RVM とは

RVM (Ruby Version Manager) は、Ruby のバージョン管理ツール。
複数の Ruby バージョンをインストール・切り替えでき、プロジェクトごとに異なるバージョンを使用可能。

2. RVM のインストール

コマンド 説明
\curl -sSL https://get.rvm.io | bash -s stable RVM のインストール
source ~/.rvm/scripts/rvm RVM の環境を適用

3. Ruby のインストール・管理

コマンド 説明
rvm list known インストール可能な Ruby のバージョン一覧を表示
rvm install 3.2.0 指定した Ruby バージョンをインストール
rvm uninstall 3.1.0 指定した Ruby バージョンをアンインストール
rvm list インストール済みの Ruby バージョン一覧を表示
rvm use 3.2.0 指定した Ruby バージョンを使用
rvm --default use 3.2.0 デフォルトの Ruby バージョンを設定
rvm current 現在使用中の Ruby バージョンを表示

4. Gemset の管理

コマンド 説明
rvm gemset list 現在の Ruby バージョンの Gemset を一覧表示
rvm gemset create mygemset Gemset を作成
rvm gemset use mygemset 指定した Gemset を使用
rvm --default gemset use mygemset デフォルトの Gemset を設定
rvm gemset delete mygemset 指定した Gemset を削除

5. プロジェクトごとの Ruby バージョン設定

コマンド 説明
echo "3.2.0" > .ruby-version プロジェクトディレクトリで Ruby バージョンを指定
echo "mygemset" > .ruby-gemset プロジェクトディレクトリで Gemset を指定
rvm use . .ruby-version.ruby-gemset を適用

6. RVM の更新・削除

コマンド 説明
rvm get stable RVM を最新の安定版に更新
rvm reload RVM の設定をリロード
rvm implode RVM を完全に削除

7. まとめ

  • RVM は Ruby のバージョンを柔軟に管理できる
  • Gemset を活用するとプロジェクトごとに独立した環境を構築できる
  • .ruby-version.ruby-gemset を設定すると、プロジェクトごとに自動でバージョンが切り替わる

RVM を適切に活用し、開発環境を整理しよう!

man rvmより引用

RVM(1)                                                    [FIXME: manual]                                                    RVM(1)

NAME
       rvm - The Ruby Version Manager

SYNOPSIS
       rvm [FLAGS] [OPTIONS] ACTION [IMPLEMENTATION[,IMPLEMENTATION[,...]]

DESCRIPTION
       RVM is a command line tool which allows us to easily install, manage and work with multiple ruby environments from
       interpreters to sets of gems.

FLAGS
       --head
           with update, updates rvm to git head version.

       --rubygems
           with update, updates rubygems for selected ruby

       --default
           with ruby select, sets a default ruby for new shells.

       --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/)

       --source
           src directory to use (~/.rvm/src/)

       --archives
           directory for downloaded files (~/.rvm/archives/)

       -S
           Specify a script file to attempt to load and run (rubydo).

       -e
           Execute code from the command line.

       -G
           root gem path to use

       --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, --patches
           With any ruby build from source, allows you to specify patch paths and patch names to be applied prior to building.
           Values should be a relative / absolute path to a patch or the name of known patch / patchset. Optionally, paths or names
           may be followed by %someinteger - e.g.  --patches mypatch%2 - where the number following the % specifies the value of
           the -p argument to patch, defaulting to two.

       -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.

ACTIONS
       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).

       do
           Executes the command against either all or a listed subset of rubies. eg. rvm do gem --version ; rvm 1.8.7,1.9.2 do rake
           --version

       env
           Displays information about an environment specified but the given ruby string. Useful for getting a sourceable path or
           an evaluatable set of shell variable declarations.

       implode
           (seppuku) removes the rvm installation completely. This means everything in $rvm_path (~/.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.
           scripts/rvm.

       update
           Upgrades rvm to the latest version. (If you experience bugs try this first with --head).

       get
           RVM get will 'get' the version you specify. This must be one of latest or head. With no arguments the rvm get help
           section will be shown..

       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.

       debug
           Show info plus additional information for common issues.

       install
           Install one or many ruby versions.  https://rvm.io/rubies/installing/

       uninstall
           Uninstall one or many ruby versions, leaves their sources.

       remove
           Uninstall one or many ruby versions and remove their sources.

       delete
           Same as remove.

       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.

       ruby
           Runs a named ruby file against specified and/or all rubies.

       gem
           Runs a gem command using selected ruby’s gem.

       rake
           Runs a rake task 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: https://rvm.io/gemsets/

       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.  https://rvm.io/rubies/list/

       package
           Install a dependency package {readline,iconv,zlib,openssl}.  https://rvm.io/packages/

       requirements
           Show additional OS specific dependencies/requirements for building various rubies.

       notes
           Display notes. Operating system specifics are now under 'requirements'.

IMPLEMENTATION
       ruby
           MRI/YARV Ruby (The Gold Standard) {1.8.x, 1.9.x, 2.0.x, 2.1.x, 2.2.x}

       jruby
           JRuby, Ruby interpreter on the Java Virtual Machine.

       rbx
           Rubinius

       truffleruby
           TruffleRuby, a high performance implementation of Ruby built on GraalVM.

       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 the default ruby (or the system ruby if a default hasn’t been set).  https://rvm.io/rubies/default/

RESOURCES
       Main web site

       Online issue-tracker

COPYING
       Copyright (c) 2009 Wayne E. Seguin

       See LICENSE file for details.

[FIXME: source]                                              07/16/2010                                                      RVM(1)