db:migrateのエラー
0. 現象
Ruby on rails のプロジェクトで、dbをマイグレーションかけようと思ったら、下記エラーに遭遇。
$ bundle exec rails db:migrate Could not find ffi-1.11.1 in any of the sources Run `bundle install` to install missing gems.
1. 解決方法
Xcodeのツールをインストールをする。
$ xcode-select --install
すると、何やらXcodeのアイコンと利用規約的なポップアップが出るので同意してインストール。 完了してから、
$ gem install ffi -v '1.11.1' --source 'https://rubygems.org/' Building native extensions. This could take a while... Successfully installed ffi-1.11.1 Parsing documentation for ffi-1.11.1 Installing ri documentation for ffi-1.11.1 Done installing documentation for ffi after 7 seconds 1 gem installed
で、bundle installしてから、bundle exec rails db:migrateも無事成功となりました。 こちらを参考にさせていただきました[感謝!]:
【解決方法】Macで gem ffi の インストール (アップデート) に 失敗する - Qiita
2. 解決方法までの道のり(1)
bundle install なさいませ、のご啓示に従いコマンド打つとさらにエラー。OMG!
$ bundle install <略> current directory: /Users/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ffi-1.11.1/ext/ffi_c /Users/user/.rbenv/versions/2.6.6/bin/ruby -I /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0 -r ./siteconf20210115-42536-3mapdz.rb extconf.rb *** 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. <略> An error occurred while installing ffi (1.11.1), and Bundler cannot continue. Make sure that `gem install ffi -v '1.11.1' --source 'https://rubygems.org/'` succeeds before bundling. In Gemfile: bootstrap-sass was resolved to 3.4.1, which depends on sassc was resolved to 2.0.1, which depends on ffi
ん?でもよく見ると、さらなるご啓示が!
3. 解決方法までの道のり(2)
でも、やっぱりエラーに。
$ gem install ffi -v '1.11.1' --source 'https://rubygems.org/' Building native extensions. This could take a while... ERROR: Error installing ffi: ERROR: Failed to build gem native extension. current directory: /Users/user/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/ffi-1.11.1/ext/ffi_c /Users/user/.rbenv/versions/2.6.6/bin/ruby -I /Users/user/.rbenv/versions/2.6.6/lib/ruby/2.6.0 -r ./siteconf20210115-42600-1m980hy.rb extconf.rb *** 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.
4. 解決方法までの道のり(3)
切り口を変えて、エラーメッセージを細切れにしてグーグル先生に聞くと。
「gem install ffi error error: invalid active developer path」 →参考サイトの通りで、解決となりましたとさ。めでたし。