4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rubyのrequire '**'で`mkdir': Permission deniedと出る時の対処法

Posted at

rubyで、nokogiriでスクレイピングしようとしたら以下のエラーが出た。
open-uriのみ記述の場合はエラーが出ないので、どうやらnokogiriが原因っぽい。

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:245:in `mkdir': Permission denied - /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14 (Errno::EACCES)
  from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:245:in `fu_mkdir'
  from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:219:in `block (2 levels) in mkdir_p'
  from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:217:in `reverse_each'
  from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:217:in `block in mkdir_p'
  from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:203:in `each'
  from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/fileutils.rb:203:in `mkdir_p'
  from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:210:in `write_gem_make_out'
  from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:132:in `build_error'
  from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:171:in `rescue in build_extension'
  from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:156:in `build_extension'
  from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:198:in `block in build_extensions'
  from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:195:in `each'
  from /Library/Ruby/Site/2.0.0/rubygems/ext/builder.rb:195:in `build_extensions'
  from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1436:in `block in build_extensions'
  from /Library/Ruby/Site/2.0.0/rubygems/user_interaction.rb:45:in `use_ui'
  from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1434:in `build_extensions'
  from /Library/Ruby/Site/2.0.0/rubygems/stub_specification.rb:60:in `build_extensions'
  from /Library/Ruby/Site/2.0.0/rubygems/basic_specification.rb:56:in `contains_requirable_file?'
  from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:925:in `block in find_inactive_by_path'
  from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:in `each'
  from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:in `find'
  from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:924:in `find_inactive_by_path'
  from /Library/Ruby/Site/2.0.0/rubygems.rb:185:in `try_activate'
  from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:132:in `rescue in require'
  from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
  from /Users/sadakoa/Desktop/main.rb:1:in `<main>'

対処

% gem update
#もし怒られたら
% sudo gem update

結果、治らない。ここで1時間ちょっと頭を悩ます。
gem installした時にrbenvにパスを通すのを忘れていたので、下記コマンドを打ってみる。

% rbenv rehash

解決した。

原因

このエラー、前も見たことがあってその時はどう解決したか覚えていないんだけど、rbenv関係のエラーだった気がする。
(間違っていたらすみません)
対処法としては

  • gemをアップデートする
  • rbenvをrehashする
  • zshでPATHが通ってるか確認する。(通ってなかったら通す)
  • いっそrbenvでrubyを入れ直す

らへんを試せば治る気がする。

4
3
0

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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?