rbenvをインストール
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
Initialized empty Git repository in /home/vagrant/.rbenv/.git/
remote: Counting objects: 2484, done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 2484 (delta 9), reused 0 (delta 0), pack-reused 2464
Receiving objects: 100% (2484/2484), 445.80 KiB | 142 KiB/s, done.
Resolving deltas: 100% (1562/1562), done.
パスを通し、ターミナル起動時に「rbenv init」する様にしておく。
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
リロード
$ source ~/.bash_profile
ruby-buildをインストール
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Initialized empty Git repository in /home/vagrant/.rbenv/plugins/ruby-build/.git/
remote: Counting objects: 5431, done.
remote: Total 5431 (delta 0), reused 0 (delta 0), pack-reused 5431
Receiving objects: 100% (5431/5431), 1013.75 KiB | 389 KiB/s, done.
Resolving deltas: 100% (3029/3029), done.
rbenvのバージョン確認
$ rbenv
rbenv 1.0.0-14-gc388331
Usage: rbenv []
Some useful rbenv commands are:
commands List all available rbenv commands
local Set or show the local application-specific Ruby version
global Set or show the global Ruby version
shell Set or show the shell-specific Ruby version
rehash Rehash rbenv shims (run this after installing executables)
version Show the current Ruby version and its origin
versions List all Ruby versions available to rbenv
which Display the full path to an executable
whence List all Ruby versions that contain the given executable
See `rbenv help ' for information on a specific command.
For full documentation, see: https://github.com/rbenv/rbenv#readme
rubyをインストールする際に必要になるパッケージをインストール
$ sudo yum install gcc make openssl-devel readline-devel
インストール可能なrubyのバージョンの一覧を確認する
$ rbenv install -l
Available versions:
:
略
:
2.2.0
2.2.1
2.2.2
2.2.3
2.2.4
2.3.0-dev
2.3.0-preview1
2.3.0-preview2
2.3.0
2.4.0-dev
:
略
:
今回はとりあえず2.2.4をインストールしてみる。
$ rbenv install 2.2.4
Downloading ruby-2.2.4.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.4.tar.bz2
error: failed to download ruby-2.2.4.tar.bz2
BUILD FAILED (CentOS release 6.7 (Final) using ruby-build 20151230)
ダウンロードに失敗したのでログを確認。
ググると、時間が一致していない事が問題らしいので、サーバ側の時間を現時刻に合わせた。(ntp入れた)
tail /tmp/ruby-build.YYYYMMDDHHIISS.XXXX.log
curl: (60) Peer certificate cannot be authenticated with known CA certificates
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
現時刻があったことを確認して、下記コマンドを再度実行。
$ rbenv install 2.2.4
Downloading ruby-2.2.4.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.4.tar.bz2
Installing ruby-2.2.4...
Installed ruby-2.2.4 to /home/vagrant/.rbenv/versions/2.2.4
デフォルトで使用するrubyのバージョンを下記の通りにする。
$ rbenv global 2.2.4
バージョンを確認(rubyコマンドが見つからない場合は、$ source ~/.bash_profileする)
$ ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
以上でインストールは完了。