CentOS6 ruby 1.9.3もとい、2.4.0を入れてみる

CentOS6.9 i368の標準だとrubyは1.8.7だったりする。

新しいものを入れてみます。

作るのに必要なパッケージを持ってくる。
# yum -y install gcc-c++ patch readline readline-devel zlib  \
              zlib-devel libyaml-devel libffi-devel openssl-devel \
              make bzip2 autoconf automake libtool bison 

RVM(Ruby Version Manager) を引っ張ってくる

# curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 24090  100 24090    0     0  14056      0  0:00:01  0:00:01 --:--:--  108k
gpg: 2017年09月11日 05時59分21秒 JSTにRSA鍵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.29.3.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:
# gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
or if it fails:
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
the key can be compared with:
https://rvm.io/mpapis.asc
    https://keybase.io/mpapis
NOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. Please downgrade or upgrade to newer version (if available) or use the second method described above
# gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
gpg: 鍵D39DC0E3をhkpからサーバーkeys.gnupg.netに要求
gpg: 鍵D39DC0E3: 公開鍵"Michal Papis (RVM signing) <mpapis@gmail.com>"を読み込みました
gpg: 絶対的に信用する鍵が見つかりません
gpg:     処理数の合計: 1
gpg:           読込み: 1  (RSA: 1)
# command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
gpg: 鍵D39DC0E3:"Michal Papis (RVM signing) <mpapis@gmail.com>"変更なし
gpg:     処理数の合計: 1
gpg:         変更なし: 1
# curl -L get.rvm.io | bash -s stable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 24090  100 24090    0     0  29111      0 --:--:-- --:--:-- --:--:-- 29111
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
Downloading https://github.com/rvm/rvm/archive/1.29.3.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.3/1.29.3.tar.gz.asc
gpg: 2017年09月11日 05時59分21秒 JSTにRSA鍵ID BF04FF17で施された署名
gpg: "Michal Papis (RVM signing) <mpapis@gmail.com>"からの正しい署名
gpg:                 別名"Michal Papis <michal.papis@toptal.com>"
gpg:                 別名"[jpeg image of size 5015]"
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.29.3.tgz'
Upgrading the RVM installation in /usr/local/rvm/
Upgrade of RVM in /usr/local/rvm/ is complete.
Upgrade Notes:
  * It looks like some old stuff is laying around RVM, you can cleanup with: rvm cleanup all
 * No new notes to display.

cleanupしろと怒られた場合は以下のとおり。rvmが見つからないときは

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

とかで環境変数を設定

# rvm cleanup all
RVM version 1.29.3 (latest) is installed yet 1.29.2 (latest) is loaded.
Please do one of the following:
  * 'rvm reload'
  * open a new shell
  * 'echo rvm_auto_reload_flag=1 >> ~/.rvmrc' # for auto reload with msg.
  * 'echo rvm_auto_reload_flag=2 >> ~/.rvmrc' # for silent auto reload.
# rvm reload
Warning! PATH is not properly set up, '/usr/local/rvm/gems/ruby-2.4.0/bin' is not at first place.
         Usually this is caused by shell initialization files. Search for 'PATH=...' entries.
         You can also re-add RVM to your profile by running: 'rvm get stable --auto-dotfiles'.
         To fix it temporarily in this shell session run: 'rvm use ruby-2.4.0'.
         To ignore this error add rvm_silence_path_mismatch_check_flag=1 to your ~/.rvmrc file.
RVM reloaded!
# rvm cleanup all
Cleaning up rvm archives
Cleaning up rvm repos
Cleaning up rvm src
Cleaning up rvm log
Cleaning up rvm tmp
Cleaning up rvm gemsets
Cleaning up rvm links
Cleanup done.
# rvm version
rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

 RVMで必要な環境変数の読み込み

# source /etc/profile.d/rvm.sh
// ★無駄な工程なのでskipしてもかまいません。
# rvm install 1.9.3
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/6/i386/ruby-1.9.3-p551.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-1.9.3-p551, this may take a while depending on your cpu(s)...
ruby-1.9.3-p551 - #downloading ruby-1.9.3-p551, 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 9813k  100 9813k    0     0   602k      0  0:00:16  0:00:16 --:--:--  573k
ruby-1.9.3-p551 - #extracting ruby-1.9.3-p551 to /usr/local/rvm/src/ruby-1.9.3-p551...
ruby-1.9.3-p551 - #applying patch /usr/local/rvm/patches/ruby/GH-488.patch.
ruby-1.9.3-p551 - #applying patch /usr/local/rvm/patches/ruby/1.9.3/CVE-2015-1855-p484.patch.
ruby-1.9.3-p551 - #applying patch /usr/local/rvm/patches/ruby/1.9.3/update-autoconf.patch.
ruby-1.9.3-p551 - #applying patch /usr/local/rvm/patches/ruby/1.9.3/openssl3.patch.
ruby-1.9.3-p551 - #applying patch /usr/local/rvm/patches/ruby/ssl_no_ec2m.patch.
ruby-1.9.3-p551 - #configuring..............................................
ruby-1.9.3-p551 - #post-configuration..
ruby-1.9.3-p551 - #compiling.............................................................
ruby-1.9.3-p551 - #installing........................
ruby-1.9.3-p551 - #making binaries executable..
ruby-1.9.3-p551 - #downloading rubygems-2.6.13
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  750k  100  750k    0     0   633k      0  0:00:01  0:00:01 --:--:--  914k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-1.9.3-p551 - #extracting rubygems-2.6.13....
ruby-1.9.3-p551 - #removing old rubygems.........
ruby-1.9.3-p551 - #installing rubygems-2.6.13..........................
ruby-1.9.3-p551 - #gemset created /usr/local/rvm/gems/ruby-1.9.3-p551@global
ruby-1.9.3-p551 - #importing gemset /usr/local/rvm/gemsets/global.gems...................
ruby-1.9.3-p551 - #generating global wrappers........
ruby-1.9.3-p551 - #gemset created /usr/local/rvm/gems/ruby-1.9.3-p551
ruby-1.9.3-p551 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-1.9.3-p551 - #generating default wrappers........
ruby-1.9.3-p551 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-1.9.3-p551 - #complete
WARNING: Please be aware that you just installed a ruby that is no longer maintained (2016-02-24), for a list of maintained rubies visit:
    http://bugs.ruby-lang.org/projects/ruby/wiki/ReleaseEngineering
Please consider upgrading to ruby-2.4.0 which will have all of the latest security patches.
Ruby was built without documentation, to build it run: rvm docs generate-ri

もうメンテナンスしません宣言。yumで拾ってこれるversionは1.8.7なんですが。仕方ないので消します。

# rvm uninstall 1.9.3
ruby-1.9.3-p551 - #removing src/ruby-1.9.3-p551..
ruby-1.9.3-p551 - #removing rubies/ruby-1.9.3-p551..
ruby-1.9.3-p551 - #removing default ruby interpreter..............

気を取り直して2.4.0をといわれたのでそれをinstall。ただコレを書いている時点で2.4.1も出ていたり….。2018 Jul現在2.5.1とかです。どんどん変わっていきます。

# rvm install 2.4.0
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/6/i386/ruby-2.4.0.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Requirements installation successful.
Installing Ruby from source to: /usr/local/rvm/rubies/ruby-2.4.0, this may take a while depending on your cpu(s)...
ruby-2.4.0 - #downloading ruby-2.4.0, 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 11.9M  100 11.9M    0     0   683k      0  0:00:17  0:00:17 --:--:-- 1027k
ruby-2.4.0 - #extracting ruby-2.4.0 to /usr/local/rvm/src/ruby-2.4.0....
ruby-2.4.0 - #configuring................................................................-
ruby-2.4.0 - #post-configuration..
ruby-2.4.0 - #compiling..................................................................|
ruby-2.4.0 - #installing.........................
ruby-2.4.0 - #making binaries executable..
ruby-2.4.0 - #downloading rubygems-2.6.13
ruby-2.4.0 - #extracting rubygems-2.6.13.....
ruby-2.4.0 - #removing old rubygems.........
ruby-2.4.0 - #installing rubygems-2.6.13..........................
ruby-2.4.0 - #gemset created /usr/local/rvm/gems/ruby-2.4.0@global
ruby-2.4.0 - #importing gemset /usr/local/rvm/gemsets/global.gems........................|
ruby-2.4.0 - #generating global wrappers........
ruby-2.4.0 - #gemset created /usr/local/rvm/gems/ruby-2.4.0
ruby-2.4.0 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.4.0 - #generating default wrappers........
ruby-2.4.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.4.0 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
# rvm use 2.4.0 --default 
Using /usr/local/rvm/gems/ruby-2.4.0
# ruby --version
ruby 2.4.0p0 (2016-12-24 revision 57164) [i686-linux]