rbenv installでconfigure: error: cannot run C compiled programs.が出た場合に対処

  • Rubyのインストール
  • rbenvが一番良さそう
  • homebrewは入ってる前提で行う


かいつまむと、$ rbenv install 2.6.3 した後にエラーが出て 必要そうなところをみてみると

configure: error: cannot run C compiled programs.

とでていた、Xcode Command Line Toolsあたりのエラー?なのか下記を参考にして

Can still install ruby 2.5.1 on my MacOS · Issue #1233 · rbenv/ruby-build

下記コマンドをうって、header package?をインストールしてやってからrbenv installしたらちゃんとrubyが入った

$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /


以下は経緯


$ brew install rbenv ruby-build

// インストール可能なrubyのバージョンを調べる
$ rbenv install -l

// 20190501時点では2.6.3が最新だったので入れてみる
$ rbenv install 2.6.3

// 下記エラーが出た


ruby-build: use openssl from homebrew
Downloading ruby-2.6.3.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.3.tar.bz2
Installing ruby-2.6.3...
ruby-build: use readline from homebrew

BUILD FAILED (OS X 10.14.4 using ruby-build 20190423)

Inspect or clean up the working tree at /var/folders/px/kk8zlmr5057cp56tp7l34l_h0000gn/T/ruby-build.20190501144337.73860
Results logged to /var/folders/px/kk8zlmr5057cp56tp7l34l_h0000gn/T/ruby-build.20190501144337.73860.log

Last 10 log lines:
checking host system type... x86_64-apple-darwin18.5.0
checking target system type... x86_64-apple-darwin18.5.0
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... configure: error: in `/var/folders/px/kk8zlmr5057cp56tp7l34l_h0000gn/T/ruby-build.20190501144337.73860/ruby-2.6.3':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
make: *** No targets specified and no makefile found.  Stop.
$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
  • もっかいrbenv install
  • rubyがちゃんと入ったので $ rbenv global 2.6.3 してやった