LoginSignup
8
8

More than 5 years have passed since last update.

bundle installがエラーになると思ったらMacOS Mojaveのアップグレードが原因だった話。

Last updated at Posted at 2019-02-09

bundle installがエラーに!

bundle installができない! エラー文の指示にしたがってもまた指示でてきてループする!
と言う感じのエラーにはまって、半日潰してしまったので備忘録として残しておきます...。

環境はこちら

ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin17]
Rails 4.2.6
MacOS Mojave 10.14

ことの発端は、RailsのPaperclipで縦横比がおかしいためImageMagickのバージョン確認をしていたこと。
rmagickとの互換性がないことがわかり、以下の記事を参考に、ImageMagickを7からImageMagick6へダウングレードしました。

imagemagick と rmagick のインストールでつまづいたときに確認する手順
https://qiita.com/DriftwoodJP/items/56e9f9265022ba7a9802

記事の指示通り進め、
imagemagick6をinstallしました。

command
$ brew install imagemagick@6

以下結果です。

command-result
Updating Homebrew...
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
\以下🍺と黄色い文字のダウンロード内容が延々と続く

ここの「xcrun: error:」エラーは、MacOS Mojaveにアップデートしたことに関するXcodeのエラーのようです。このエラーが原因だった模様。後ほど言及します。

無限ループのエラーに遭遇

ダウングレードには成功した(バージョン確認できた)のですが、rmagickをアンインストールして以下のコマンドを打ったところ思わぬエラーが...。

command
PKG_CONFIG_PATH=/usr/local/opt/imagemagick@6/lib/pkgconfig bundle install --path vendor/bundle

以下表示された結果

command-result
Fetching gem metadata from https://rubygems.org/.......
Fetching rake 12.3.2
Installing rake 12.3.2
Fetching concurrent-ruby 1.1.4
Installing concurrent-ruby 1.1.4
Fetching i18n 0.9.5
Installing i18n 0.9.5
Fetching json 1.8.6
Installing json 1.8.6 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/***/projects/***/vendor/bundle/ruby/2.3.0/gems/json-1.8.6/ext/json/ext/generator
/Users/***/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20190208-54374-blljf9.rb extconf.rb
creating Makefile

current directory: /Users/***/projects/***/vendor/bundle/ruby/2.3.0/gems/json-1.8.6/ext/json/ext/generator
make "DESTDIR=" clean
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at:
/Library/Developer/CommandLineTools/usr/bin/xcrun

current directory: /Users/***/projects/***/vendor/bundle/ruby/2.3.0/gems/json-1.8.6/ext/json/ext/generator
make "DESTDIR="
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at:
/Library/Developer/CommandLineTools/usr/bin/xcrun

make failed, exit code 1

Gem files will remain installed in /Users/***/projects/***/vendor/bundle/ruby/2.3.0/gems/json-1.8.6 for inspection.
Results logged to /Users/***/projects/***/vendor/bundle/ruby/2.3.0/extensions/x86_64-darwin-17/2.3.0-static/json-1.8.6/gem_make.out

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

In Gemfile:
  rails was resolved to 4.2.6, which depends on
    actionmailer was resolved to 4.2.6, which depends on
      actionpack was resolved to 4.2.6, which depends on
        actionview was resolved to 4.2.6, which depends on
          rails-dom-testing was resolved to 1.0.9, which depends on
            rails-deprecated_sanitizer was resolved to 1.0.3, which depends on
              activesupport was resolved to 4.2.6, which depends on
                json

上のエラー文の中の最後のこちらのエラーに悩まされました。

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

json1.8.6をインストールしろという指示

json 1.8.6をinstallしろとのこと。よく分からんけど、とりあえず指示にしたがっておこう。ということで、この指示通りにinstallしようと以下を実行

command
$ gem install json -v '1.8.6' --source 'https://rubygems.org/'

すると結果がこちら。

command-result
ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted @ chmod_internal - /Users/***/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/json-1.8.6/tests/test_json.rb

ん?、permittionがない?
bundle doctorで確認してみると、すべてのgemがmissingになってしまっている。
よし、sudo で無理やりするしかないか、と思い以下を実行すると、

command
$ sudo gem install json -v '1.8.6' --source 'https://rubygems.org/'
commad-result
Password:
Fetching json-1.8.1.gem
Building native extensions. This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

/以下最初のエラー文と同じ/
An error occurred while installing json (1.8.6), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.6' --source 'https://rubygems.org/'` succeeds before bundling.
/以下も同じ/

またもやgem install json しろという無限ループに。

この時点で、bundle installbundle updateもできなくなり、rails sもできなくなりました。 sudo でも動かなくなり。。。やばい、何もできない。。。

ちなみに、Rails sをすると、、、

command-result
Could not find json-1.8.6 in any of the sources
Run `bundle install` to install missing gems.

とのこと。bundle installができないんですよ〜エラーさん。。。

いろいろと試す

ということでいろいろとエラー文でググりまくり解決策を見つけようと試みましたがどれもうまくいかず。

これも試す

Can't install JSON gem
https://stackoverflow.com/questions/5216278/cant-install-json-gem

bundle execも試す

Why am I not able to install JSON gem?
https://stackoverflow.com/questions/42409173/why-am-i-not-able-to-install-json-gem?rq=1

こちらも確認するも問題なし

bundle install しようとしたら ruby のバージョン違くてコケた話
https://qiita.com/white_aspara25/items/d5e19b82be17048d9215

仕方なくgit resetして一つ前のコミットに戻るも、環境は変わらずエラーは解消せず。

MacOS Mojaveのアップグレードが関係する?

英語でググってみたりStack overflow探したりするなかでこちらの記事を発見。

Rails: macOSをMojaveにアップグレード後bundle installがエラーになった場合の対応方法
https://techracho.bpsinc.jp/hachi8833/2018_10_10/62963

ん、そういや最近Mojaveにアップグレードしたぞ。。。
Xcode普段使わないのにこんなところでエラーの原因になってるとは。。

まさにこの記事の通りの状態でした。
/Library/Developer/CommandLineToolsをローカルで探すもフォルダがないことがわかり、この記事の指示の前に以下のコマンドでインストール。

command
$ xcode-select --install

そして記事の通り以下を実行すると無事インストール画面のポップアップがでてきました。

command
$ sudo open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

インストール終了後、sudo bundle installをすると、見事成功。

json1.8.6というversionのエラーと、Mojaveのアップグレードがどう関係していたのかは未だ謎なのですが、MacOS Mojaveのアップグレード後に起きうるエラーのようなので試してみてください。

8
8
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8