旅するえんじにあ - Engineers to Travel -

旅するエンジニアの気まま備忘録

【Ruby】RVMでRubyのインストールとバージョン管理

最近CapistranoでデプロイをするためにRubyが必要になったので 必要に迫られてインストール

どうにも昔からRubyのインストールには依存やらなんやらでつまずくことが多かった。 PHPみたいな感じでRubyもパッケージ管理をするためにRVMを入れることに。

まずは必要パッケージをインストール

# sudo yum install -y git zlib-devel perl-ExtUtils-MakeMaker httpd httpd-devel openssl-devel libyaml-devel libxml2-devel libxslt-devel libffi-devel readline-devel pcre-devel iconv-devel sqlite-devel mysql mysql-server m
ysql-devel postgresql postgresql-server postgresql-devel curl-devel nkf

そしてインストール

# curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/wayneeseguin/rvm/archive/1.26.3.tar.gz
Downloading https://github.com/wayneeseguin/rvm/releases/download/1.26.3/1.26.3.tar.gz.asc
gpg: ディレクトリー「/root/.gnupg」ができました
gpg: 新しい構成ファイル「/root/.gnupg/gpg.conf」ができました
gpg: 警告: 「/root/.gnupg/gpg.conf」のオプションは起動している間、有効になりません
gpg: 鍵輪「/root/.gnupg/pubring.gpg」ができました
gpg: 2014年11月18日 10時09分57秒 JSTRSA鍵ID BF04FF17で施された署名
gpg: 署名を検査できません: No public key
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found.
Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).

GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.26.3.tgz' - 'https://github.com/wayneeseguin/rvm/releases/download/1.26.3/1.26.3.tar.gz.asc'!
try downloading the signatures:

    sudo gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | sudo gpg2 --import -

the key can be compared with:

    https://rvm.io/mpapis.asc
    https://keybase.io/mpapis

なんか出てきた。

try downloading the signatures:

    sudo gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | sudo gpg2 --import -

ふむ、 とりあえず上記コマンドを試してみる

# sudo gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
gpg: 鍵輪「/root/.gnupg/secring.gpg」ができました
gpg: 鍵D39DC0E3をhkpからサーバーkeys.gnupg.netに要求
gpg: /root/.gnupg/trustdb.gpg: 信用データベースができました
gpg: 鍵D39DC0E3: 公開鍵“Michal Papis (RVM signing) ”を読み込みました
gpg:     処理数の合計: 1
gpg:           読込み: 1  (RSA: 1)

# command curl -sSL https://rvm.io/mpapis.asc | sudo gpg2 --import -
gpg: 鍵D39DC0E3:“Michal Papis (RVM signing) ”変更なし
gpg:     処理数の合計: 1
gpg:         変更なし: 1

変更なしって出てきた。

もう一度curlでコマンドを打つと

# curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/wayneeseguin/rvm/archive/1.26.3.tar.gz
Downloading https://github.com/wayneeseguin/rvm/releases/download/1.26.3/1.26.3.tar.gz.asc
gpg: 2014年11月18日 10時09分57秒 JSTRSA鍵ID BF04FF17で施された署名
gpg: “Michal Papis (RVM signing) ”からの正しい署名
gpg: 警告: この鍵は信用できる署名で証明されていません!
gpg:       この署名が所有者のものかどうかの検証手段がありません。
主鍵の指紋: 409B 6B17 96C2 7546 2A17  0311 3804 BB82 D39D C0E3
副鍵の指紋: 62C9 E5F4 DA30 0D94 AC36  166B E206 C29F BF04 FF17
GPG verified '/usr/local/rvm/archives/rvm-1.26.3.tgz'
Creating group 'rvm'

Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.

# Administrator,
#
#   Thank you for using RVM!
#   We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.

In case of problems: http://rvm.io/help and https://twitter.com/rvm_io

ってことでRVMが使えるようになったっぽい /etc/profile.d/以下にrvm.shが出来上がってるので、パスを通しておく

# source /etc/profile.d/rvm.sh

バージョンの確認

# rvm -v
rvm 1.26.3 (latest) by Wayne E. Seguin , Michal Papis  https://rvm.io/

どのバージョンのRubyが使えるのか確認

# rvm list known


# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p598]
[ruby-]2.1.4
[ruby-]2.1[.5]
[ruby-]2.1-head
ruby-head

# for forks use: rvm install ruby-head- --url https://github.com/github/ruby.git --branch 2.1

# JRuby
jruby-1.6.8
jruby[-1.7.16.1]
jruby-head

# Rubinius
rbx-1.3.3
rbx-2.0.0
rbx-2.1.1
rbx[-2.2.10]
rbx-head

# Opal
opal

# Minimalistic ruby implementation - ISO 30170:2012
mruby[-head]

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# GoRuby
goruby

# Topaz
topaz

# MagLev
maglev[-head]
maglev-1.0.0

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby
ironruby[-1.1.3]
ironruby-head

とりあえず2.1.4あたりをインストールしてみる。

# rvm install ruby-2.1.4

インストールしたら選択する

rvm use ruby-2.1.4

バージョン確認

# ruby -v
ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-linux]

いやー楽になったもんだ。