5
4

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.

[macOS Sierra] nokogiri インストール中のエラー "Permission denied @ dir_s_mkdir" の 1解決手法

Last updated at Posted at 2017-05-19

はじめに

rubyでスクレイピングを行えるnokogiriのインストールでよくハマることが多い。
解決方法の記事が山ほどあるけど、その中の1つとしてあげる。

環境

macOS + rbenvの環境。

OS: macOS 10.12.4 (Sierra)
Ruby: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
nokogiri: nokogiri 1.7.2 with native extensions

エラー内容

$ gem install nokogiri -v '1.7.2'

Building native extensions.  This could take a while...
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied @ dir_s_mkdir - /Users/username/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/nokogiri-1.7.2

EACESSはアクセス権限系のエラー。
パーミッションか所有者?

原因

所有者がrootになっていた。

$ ls -al
total 0
drwxr-xr-x  12 root  staff  408  4 29 17:44 .
drwxr-xr-x   3 root  staff  102  4 29 16:52 ..
drwxr-xr-x   5 root  staff  170  4 29 16:55 bindex-0.5.0
drwxr-xr-x   5 root  staff  170  4 29 16:55 byebug-9.0.6
drwxr-xr-x   6 root  staff  204  4 29 16:55 ffi-1.9.18
drwxr-xr-x   6 root  staff  204  4 29 16:54 nio4r-2.0.0
drwxr-xr-x   6 root  staff  204  4 29 16:53 nokogiri-1.7.1
drwxr-xr-x   6 root  staff  204  4 29 16:55 puma-3.8.2
drwxr-xr-x   4 root  staff  136  4 29 17:44 rmagick-2.16.0
drwxr-xr-x   6 root  staff  204  4 29 16:55 sqlite3-1.3.13
drwxr-xr-x   6 root  staff  204  4 29 16:56 therubyracer-0.12.3
drwxr-xr-x   5 root  staff  170  4 29 16:54 websocket-driver-0.6.5

解決

chrootで所有者をユーザに戻した。

$ chown -R username /Users/username/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/extensions/

その他

.rbenvごと所有者を変えてもいいかもしれない。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?