[Rails]therubyracerのインストールができない!(M1Mac)

問題

bundle install したら…

$ bundle install
...
(中略)
Installing therubyracer 0.12.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/therubyracer-0.12.3/ext/v8
/Users/yoshitakakato/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20210914-94689-1gfvj2z.rb extconf.rb --with-v8-dir=/opt/homebrew/opt/v8
checking for -lpthread... yes
checking for -lobjc... yes
checking for v8.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/yoshitakakato/.rbenv/versions/2.5.1/bin/$(RUBY_BASE_NAME)
	--with-pthreadlib
	--without-pthreadlib
	--with-objclib
	--without-objclib
	--enable-debug
	--disable-debug
	--with-v8-dir
	--with-v8-include
	--without-v8-include=${v8-dir}/include
	--with-v8-lib
	--without-v8-lib=${v8-dir}/lib
/Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:50:in `configure': By using --with-system-v8, you have chosen to use the version
(Libv8::Location::System::NotFoundError)
of V8 found on your system and *not* the one that is bundled with
the libv8 rubygem.

However, your system version of v8 could not be located.

Please make sure your system version of v8 that is compatible
with 3.16.14.19 installed. You may need to use the
--with-v8-dir option if it is installed in a non-standard location
	from /Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/lib/libv8.rb:7:in `configure_makefile'
	from extconf.rb:32:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/-darwin-20/2.5.0/therubyracer-0.12.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/therubyracer-0.12.3 for inspection.
Results logged to /Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/-darwin-20/2.5.0/therubyracer-0.12.3/gem_make.out

An error occurred while installing therubyracer (0.12.3), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.12.3' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  therubyracer

therubyracerがインストールできていない模様..

「gem install therubyracer -v ‘0.12.3’ –source ‘https://rubygems.org/’」

これをやれと書いてあるのでやってみると…

$ gem install therubyracer -v '0.12.3' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
ERROR:  Error installing therubyracer:
	ERROR: Failed to build gem native extension.

    current directory: /Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/therubyracer-0.12.3/ext/v8
/Users/yoshitakakato/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20210915-94802-vd6n4n.rb extconf.rb
checking for -lpthread... yes
checking for -lobjc... yes
checking for v8.h... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/yoshitakakato/.rbenv/versions/2.5.1/bin/$(RUBY_BASE_NAME)
	--with-pthreadlib
	--without-pthreadlib
	--with-objclib
	--without-objclib
	--enable-debug
	--disable-debug
	--with-v8-dir
	--without-v8-dir
	--with-v8-include
	--without-v8-include=${v8-dir}/include
	--with-v8-lib
	--without-v8-lib=${v8-dir}/lib
/Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:50:in `configure': By using --with-system-v8, you have chosen to use the version  (Libv8::Location::System::NotFoundError)
of V8 found on your system and *not* the one that is bundled with
the libv8 rubygem.

However, your system version of v8 could not be located.

Please make sure your system version of v8 that is compatible
with 3.16.14.19 installed. You may need to use the
--with-v8-dir option if it is installed in a non-standard location
	from /Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/libv8-3.16.14.19/lib/libv8.rb:7:in `configure_makefile'
	from extconf.rb:32:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/-darwin-20/2.5.0/therubyracer-0.12.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/therubyracer-0.12.3 for inspection.
Results logged to /Users/yoshitakakato/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/-darwin-20/2.5.0/therubyracer-0.12.3/gem_make.out

これでも失敗してる…

解決

まずは以下のコマンドでlibv8 をバージョン指定してインストールする。

gem install libv8 -v '3.16.14.19' -- --with-system-v8

参照:https://stackoverflow.com/questions/65810530/unable-to-install-therubyracer-v0-12-3-gem-in-m1-macbook-pro

上記のサイトにあったコマンドを実行してみた。

gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15

すると…

$ gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15
Building native extensions with: '--with-v8-dir=/usr/local/opt/v8@3.15'
This could take a while...
Successfully installed therubyracer-0.12.3
Parsing documentation for therubyracer-0.12.3
Installing ri documentation for therubyracer-0.12.3
Done installing documentation for therubyracer after 0 seconds
1 gem installed

インストールできてる!!

もう一度bundle install

$ bundle install
...
(中略)
Bundle complete! 83 Gemfile dependencies, 463 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

完了!

タイトルとURLをコピーしました