CentOS7にrbenvでRubyをインストールする
Gitのインストール
// 入っているか確認する $ git --version -bash: git: command not found // gitのインストール $ sudo yum -y install git
rbenvのインストール
(rbenv)https://github.com/rbenv/rbenvとは、rubyのバージョンを簡単に切り替えてくれる。 複数のバージョンを管理できるツール。
// git cloneする $ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv // pathを通す $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile // 初期化する $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile // シェルの再起動をして内容を反映 $ exec $SHELL -l $ rbenv --version rbenv 1.1.1-39-g59785f6
rbenvはインストールできた。
ruby-buildをclone
rbenvのプラグインだそうで。 こちらの記事が詳しく書いてある。
rbenv + ruby-build はどうやって動いているのか - takatoshiono's blog
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
rubyが使えるようになるまで
rbenvでインストールできるリストを見る。 指定すれば複数のrubyのバージョンをインストールできる。
$ rbenv install --list Available versions: ... (略) // Ruby 2.5.0の安定版をインストール $ rbenv install 2.5.0-rc1 Downloading ruby-2.5.0-rc1.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0-rc1.tar.bz2 Installing ruby-2.5.0-rc1... BUILD FAILED (CentOS Linux 7 using ruby-build 20180822-6-g44f0f53) Inspect or clean up the working tree at /tmp/ruby-build.20180904003149.6259 Results logged to /tmp/ruby-build.20180904003149.6259.log Last 10 log lines: installing rdoc: /home/vagrant/.rbenv/versions/2.5.0-rc1/share/ri/2.5.0/system installing capi-docs: /home/vagrant/.rbenv/versions/2.5.0-rc1/share/doc/ruby The Ruby readline extension was not compiled. ERROR: Ruby install aborted due to missing extensions Try running `yum install -y readline-devel` to fetch missing dependencies. Configure options used: --prefix=/home/vagrant/.rbenv/versions/2.5.0-rc1 LDFLAGS=-L/home/vagrant/.rbenv/versions/2.5.0-rc1/lib CPPFLAGS=-I/home/vagrant/.rbenv/versions/2.5.0-rc1/include
失敗した。
以下に記載してあるように、エラーを見てみると、、、yum install -y readline-devel
しろって書いてある。
他のパッケージとの依存関係でエラーになったぽい。
ERROR: Ruby install aborted due to missing extensions Try running `yum install -y readline-devel` to fetch missing dependencies.
試してみる。
$ sudo yum install -y readline-devel
もう一度トライ
$ rbenv install 2.5.0-rc1 Downloading ruby-2.5.0-rc1.tar.bz2... -> https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0-rc1.tar.bz2 Installing ruby-2.5.0-rc1... Installed ruby-2.5.0-rc1 to /home/vagrant/.rbenv/versions/2.5.0-rc1
できた!
$ rbenv versions 2.5.0-rc1 $ rbenv global 2.5.0-rc1 $ ruby -v ruby 2.5.0rc1 (2017-12-14 trunk 61243) [x86_64-linux]