原因
何バージョンか前に32bit版のDebian GNU/Linuxをバージョンアップで64bit版に変えていたため、32ビットのアーキテクチャia32と認識されていたらしい。アーキテクチャをamd64に統一したら、うまくインストールできた。
エラー情況
タイトルのような環境でtherubyracerのインストールが失敗する。
/usr/local/rbenv/shims/gem install therubyracer
Building native extensions. This could take a while...
ERROR: Error installing therubyracer:
ERROR: Failed to build gem native extension.
current directory: /usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.3/ext/v8
/usr/local/rbenv/versions/2.4.0/bin/ruby -r ./siteconf20170205-30590-19r0fc3.rb extconf.rb
checking for -lpthread... yes
creating Makefile
current directory: /usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.3/ext/v8
make "DESTDIR=" clean
current directory: /usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.3/ext/v8
make "DESTDIR="
compiling accessor.cc
cc1plus: warning: command line option ‘-Wimplicit-int’ is valid for C/ObjC but not for C++
cc1plus: warning: unrecognized command line option "-Wno-self-assign"
cc1plus: warning: unrecognized command line option "-Wno-constant-logical-operand"
cc1plus: warning: unrecognized command line option "-Wno-parentheses-equality"
cc1plus: warning: unrecognized command line option "-Wno-tautological-compare"
〜略〜
linking shared-object v8/init.so
g++: error: /usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/libv8-3.16.14.17-x86_64-linux/vendor/v8/out/ia32.release/obj.target/tools/gyp/libv8_base.a: そのようなファイルやディレクトリはありません
g++: error: /usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/libv8-3.16.14.17-x86_64-linux/vendor/v8/out/ia32.release/obj.target/tools/gyp/libv8_snapshot.a: そのようなファイルやディレクトリはありません
Makefile:257: recipe for target 'init.so' failed
make: *** [init.so] Error 1
make failed, exit code 2
Gem files will remain installed in /usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.3 for inspection.
Results logged to /usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-linux/2.4.0-static/therubyracer-0.12.3/gem_make.out
これをインストールしているマシンはx86_64なのだけど、なぜかia32を参照している。実際にはx64のファイルが存在する。
# ls /usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/libv8-3.16.14.17-x86_64-linux/vendor/v8/out/x64.release/obj.target/tools/gyp/
libpreparser_lib.a libv8_base.a libv8_nosnapshot.a libv8_snapshot.a
そこで、/usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.3/ext/v8/Makefileのia32.releaseとなっている部分をx64.releaseと変えてコンパイルすると別のエラーがでる。
% cd /usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.3/ext/v8
% make
compiling accessor.cc
cc1plus: warning: command line option ‘-Wimplicit-int’ is valid for C/ObjC but not for C++
cc1plus: warning: unrecognized command line option "-Wno-self-assign"
cc1plus: warning: unrecognized command line option "-Wno-constant-logical-operand"
cc1plus: warning: unrecognized command line option "-Wno-parentheses-equality"
cc1plus: warning: unrecognized command line option "-Wno-tautological-compare"
〜省略〜
linking shared-object v8/init.so
/usr/bin/ld: i386:x86-64 アーキテクチャ (入力ファイル`/usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/libv8-3.16.14.17-x86_64-linux/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a(api.o)') は i386 出力と互換性がありません
/usr/bin/ld: i386:x86-64 アーキテクチャ (入力ファイル`/usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/libv8-3.16.14.17-x86_64-linux/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a(bootstrapper.o)') は i386 出力と互換性がありません
〜省略〜
RKNS_9ArgumentsE+0x0 (type R_X86_64_PC32)" goes out of range
/usr/bin/ld: /usr/local/rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/libv8-3.16.14.17-x86_64-linux/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a(externalize-string-extension.o): ファイルクラス ELFCLASS64 は ELFCLASS32 と互換性がありません
/usr/bin/ld: 最終リンクに失敗しました: 誤った形式のファイルです
collect2: error: ld returned 1 exit status
Makefile:257: recipe for target 'init.so' failed
make: *** [init.so] Error 1
解決していないけどここまで