Help us understand the problem. What is going on with this article?

rails newでErrno::EACCES: Permission denied @ dir_s_mkdir -の対処法

More than 1 year has passed since last update.

起こったエラー

久しぶりに新しいアプリケーションを作ろうとしたところ、「Errno::EACCES: Permission denied @ dir_s_mkdir -」のエラーが出た。

Errno::EACCES: Permission denied @ dir_s_mkdir -
/Users/[username]/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-17/2.5.0-static/msgpack-1.2.6
An error occurred while installing msgpack (1.2.6), and Bundler cannot continue.
Make sure that `gem install msgpack -v '1.2.6' --source 'https://rubygems.org/'` succeeds before
bundling.
$ gem install msgpack -v '1.2.6'

エラーにある通り上記のようにgemをインストールしまくったら解決するが、本質的な解決ではないので、解決策を探った。

解決策

/Users/[username]/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-17/2.5.0-static/msgpack-1.2.6
の権限をusernameに変える

解決に至った理由

エラー文を読むと

Errno::EACCES: Permission denied @ dir_s_mkdir -
/Users/[username]/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/extensions/x86_64-darwin-17/2.5.0-static/msgpack-1.2.6

permission deniedなので、
/Users/[username]/(中略)/x86_64-darwin-17/2.5.0-static/msgpack-1.2.6
の権限がないですよと怒られている。
→権限をusernameに変えてあげればいい!

手順

①エラーに出ているディレクトリにいき、$ls -laで権限を見る。

案の定、全てrootになっている。

[username]-Macbook:2.5.0-static [username]$ ls -la
total 0
drwxr-xr-x  24 root  staff  768  2 16 15:44 .
drwxr-xr-x   3 root  staff   96  2 16 14:26 ..
drwxr-xr-x   5 root  staff  160  2 16 15:37 bcrypt-3.1.12
drwxr-xr-x   7 root  staff  224  2 16 15:14 bigdecimal-1.4.3
drwxr-xr-x   5 root  staff  160  2 16 15:37 bindex-0.5.0
drwxr-xr-x   5 root  staff  160  2 16 15:37 byebug-10.0.2
drwxr-xr-x   5 root  staff  160  2 16 15:42 byebug-11.0.0
drwxr-xr-x   6 root  staff  192  2 16 15:14 date-2.0.0
drwxr-xr-x   6 root  staff  192  2 16 15:14 etc-1.0.1
drwxr-xr-x   6 root  staff  192  2 16 15:39 ffi-1.10.0
drwxr-xr-x   6 root  staff  192  2 16 15:15 io-console-0.4.7
drwxr-xr-x   6 root  staff  192  2 16 15:41 kgio-2.11.2
drwxr-xr-x   6 root  staff  192  2 16 15:42 mysql2-0.4.10
drwxr-xr-x   6 root  staff  192  2 16 15:42 mysql2-0.5.2
drwxr-xr-x   6 root  staff  192  2 16 14:27 nio4r-2.3.1
drwxr-xr-x   6 root  staff  192  2 16 14:27 nokogiri-1.10.1
drwxr-xr-x   6 root  staff  192  2 16 15:15 openssl-2.1.2
drwxr-xr-x   6 root  staff  192  2 16 15:15 psych-3.1.0
drwxr-xr-x   6 root  staff  192  2 16 15:43 puma-3.12.0
drwxr-xr-x   6 root  staff  192  2 16 15:43 raindrops-0.19.0
drwxr-xr-x   5 root  staff  160  2 16 15:16 stringio-0.0.2
drwxr-xr-x   6 root  staff  192  2 16 15:44 unicorn-5.4.1
drwxr-xr-x   5 root  staff  160  2 16 15:36 websocket-driver-0.6.5
drwxr-xr-x   5 root  staff  160  2 16 14:27 websocket-driver-0.7.0

② でusernameを確認する。

$ whoami
=> username

コマンドを打って出てきたものがご自身のusernameになります。

③権限をusernameに変更する。

$ sudo chown -R username .

こちらのコマンドで現在のディレクトリの権限をusernameに変更できる。

④再度、権限を確認する

$ ls -la

↓結果

[username]-Macbook:2.5.0-static [username]$ ls -la
total 0
drwxr-xr-x  24 [username]  staff  768  2 16 15:44 .
drwxr-xr-x   3 root    staff   96  2 16 14:26 ..
drwxr-xr-x   5 [username]  staff  160  2 16 15:37 bcrypt-3.1.12
drwxr-xr-x   7 [username]  staff  224  2 16 15:14 bigdecimal-1.4.3
drwxr-xr-x   5 [username]  staff  160  2 16 15:37 bindex-0.5.0
drwxr-xr-x   5 [username]  staff  160  2 16 15:37 byebug-10.0.2
drwxr-xr-x   5 [username]  staff  160  2 16 15:42 byebug-11.0.0
(省略)

直りました!
rails newをやってもエラーなし!

参考記事
・Errno::EACCES: Permission denied @ dir_s_mkdir が出たので対処した
https://mimikun.hatenablog.jp/entry/2018/03/22/221950

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした