Blank?=False

ゆるゆる仕事したいフリーランスエンジニアの記事

CentOS7でrbenv installでエラーが出た話

f:id:stonebeach-dakar:20160608212025j:plain

CentOS7でrbenvをインストールして、さあRubyをインストールしよう!
としたら、こんなエラーが出てきてできませんでした。

対応を備忘録として残します。

BUILD FAILED (CentOS Linux 7 using ruby-build 20160602-13-gd0a3219)

Inspect or clean up the working tree at /tmp/ruby-build.20160710174759.18615
Results logged to /tmp/ruby-build.20160710174759.18615.log

Last 10 log lines:
checking for ruby... false
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/ruby-build.20160710174759.18615/ruby-2.3.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

まずrbenvとは

Rubyのバージョン管理ツールで、複数のRubyのバージョンを共存させ、必要なときにバージョンを切り替える事ができるもの。 rvmというバージョン管理ツールもあるので、その辺はお好みという感じ。

基本的にbrew install,apt-get,yum installなどのパッケージ管理システムは、1つだけしかRubyをインストール出来ません。。
詳細はググろう。

エラーメッセージの内容から分析

こんなんでてますので、ちゃちゃっとログ・ファイルを確認してみましょ。

Inspect or clean up the working tree at /tmp/ruby-build.20160710174759.18615
Results logged to /tmp/ruby-build.20160710174759.18615.log


ruby-build.20160710174759.18615.log

/tmp/ruby-build.20160710174759.18615 /
/tmp/ruby-build.20160710174759.18615/ruby-2.3.1 /tmp/ruby-build.20160710174759.18615 /
checking for ruby... false
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/ruby-build.20160710174759.18615/ruby-2.3.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

no acceptable C compiler found in $PATH なので、CコンパイラのPATHが通ってないよ!ってことかな。

そういえば、Cコンパイラのインストール忘れてた!

Cコンパイラのインストール

Cコンパイラというのは、C言語ソースコードから実行ファイルを作るためのツールです。
Rubyの実装は、C言語で作成されているので、C言語から実行ファイルを作れるものが必要なんですね。

以下のコマンドでCコンパイラgccをインストール。

$ sudo yum -y install gcc

解決

というわけでコレで解決。

$ rbenv install 2.3.1
Downloading ruby-2.3.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.bz2
Installing ruby-2.3.1...
Installed ruby-2.3.1 to /usr/local/src/rbenv/versions/2.3.1

バージョンを確認。

 $rbenv versions
  2.3.1

問題なし!