読者です 読者をやめる 読者になる 読者になる

Pep's Diary

いろんなことを共有していきたいと思います。たまに持論を言います

【rails】rails g controllerをした時に Could not find nokogiri-1.7.1 in any of the sources が出た時の対処法

rails g controller [コントローラー名][アクション名]をコマンドで入力した時に、

/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.3/lib/bundler/spec_set.rb:87:in `block in materialize': Could not find nokogiri-1.7.1 in any of the sources (Bundler::GemNotFound)

from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.3/lib/bundler/spec_set.rb:80:in `map!'

from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.3/lib/bundler/spec_set.rb:80:in `materialize'

from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.3/lib/bundler/definition.rb:176:in `specs'

from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.3/lib/bundler/definition.rb:235:in `specs_for'

from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.3/lib/bundler/definition.rb:224:in `requested_specs'

from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.3/lib/bundler/runtime.rb:118:in `block in definition_method'

from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.3/lib/bundler/runtime.rb:19:in `setup'

from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.3/lib/bundler.rb:100:in `setup'

from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.14.3/lib/bundler/setup.rb:20:in `<top (required)>'

from /Users/UserName/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /Users/UserName/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /Users/UserName/ProjectName/vendor/bundle/gems/spring-2.0.1/lib/spring/commands.rb:33:in `<module:Spring>'

from /Users/UserName/ProjectName/vendor/bundle/gems/spring-2.0.1/lib/spring/commands.rb:4:in `<top (required)>'

from /Users//.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /Users/UserName/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /Users/UserName/ProjectName/vendor/bundle/gems/spring-2.0.1/lib/spring/server.rb:9:in `<top (required)>'

from /Users/UserName/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /Users/UserName/.rbenv/versions/2.4.0/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /Users/UserName/ProjectName/vendor/bundle/gems/spring-2.0.1/lib/spring/client/server.rb:9:in `call'

from /Users/UserName/ProjectName/vendor/bundle/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'

from /Users/UserName/ProjectName/vendor/bundle/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'

from /Users/UserName/ProjectName/vendor/bundle/gems/spring-2.0.1/bin/spring:49:in `<main>' 

 

 こんな感じのエラーが出て、コマンドが使えない状態になって詰んだ。

 

解決方法
$ rbenv exec gem install bundler
$ rbenv rehash
$ bundle install

 なんかよくわからないけど、これでいけた。

 

参考

Could not find XXXX in any of the sources エラーの修正方法 - Qiita