2
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.

rbenvでbundlerをインストールしようとするとPermission denied

Posted at

対象バージョン

  • Mac OS Hight Sierra 10.13.5(17F77)
  • rbenv 1.1.1
  • rbenv version -> 2.4.2

現象

rbenv環境下でrailsの環境を構築しようかと、bundlerをインストールしようとした所、
Permission deniedが出るようになっていました。

$ gem install bundler
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied @ rb_sysopen - /Users/mitsuaki1229/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/bundler-1.16.2/CHANGELOG.md

対応

ruby/gems/バージョン番号/配下の所有者を一通り確認

gems

$ ls -ltr /Users/mitsuaki1229/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems
total 0
drwxr-xr-x   3 mitsuaki1229  staff   96  9 23  2017 rdoc-5.0.0
drwxr-xr-x   8 mitsuaki1229  staff  256  9 23  2017 net-telnet-0.1.1
drwxr-xr-x  12 mitsuaki1229  staff  384  9 23  2017 did_you_mean-1.1.0
drwxr-xr-x   4 root          staff  128  9 23  2017 slack-notifier-1.5.1
drwxr-xr-x   6 root          staff  192  9 23  2017 CFPropertyList-2.3.5
drwxr-xr-x  17 root          staff  544  9 23  2017 nanaimo-0.2.3
drwxr-xr-x   7 root          staff  224  9 23  2017 colored2-3.1.2

~ 省略 ~

drwxr-xr-x   7 root          staff  224  6 24 22:58 i18n-1.0.1
drwxr-xr-x  13 root          staff  416  6 24 22:58 power_assert-1.1.3
drwxr-xr-x   8 root          staff  256  6 24 22:58 railties-5.2.0
drwxr-xr-x  14 root          staff  448  6 24 22:58 retriable-3.1.2
drwxr-xr-x  17 root          staff  544  6 24 22:58 simctl-1.6.5
drwxr-xr-x   7 root          staff  224  6 24 22:58 websocket-driver-0.7.0
drwxr-xr-x  13 mitsuaki1229  staff  416  6 24 23:10 mimemagic-0.3.2
drwxr-xr-x  12 mitsuaki1229  staff  384  6 24 23:11 marcel-0.3.2
drwxr-xr-x   9 mitsuaki1229  staff  288  6 24 23:11 activestorage-5.2.0

extensions

$ ls -ltr /Users/mitsuaki1229/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/extensions/
total 0
drwxr-xr-x  3 root  staff  96  9 23  2017 x86_64-darwin-16

doc

$ ls -ltr  /Users/mitsuaki1229/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/doc/
drwxr-xr-x  3 root          staff   96  9 23  2017 slack-notifier-1.5.1
drwxr-xr-x  3 root          staff   96  9 23  2017 colored2-3.1.2
drwxr-xr-x  3 root          staff   96  9 23  2017 claide-1.0.2
drwxr-xr-x  3 root          staff   96  9 23  2017 CFPropertyList-2.3.5
drwxr-xr-x  3 root          staff   96  9 23  2017 nanaimo-0.2.3
drwxr-xr-x  3 root          staff   96  9 23  2017 xcodeproj-1.5.1
drwxr-xr-x  3 root          staff   96  9 23  2017 xcpretty-0.2.8
drwxr-xr-x  3 root          staff   96  9 23  2017 terminal-notifier-1.8.0

~ 省略 ~

drwxr-xr-x  2 mitsuaki1229  staff   64  6 24 23:43 activestorage-5.2.0
drwxr-xr-x  2 mitsuaki1229  staff   64  6 24 23:43 activesupport-5.2.0
drwxr-xr-x  2 mitsuaki1229  staff   64  6 24 23:43 arel-9.0.0
drwxr-xr-x  2 mitsuaki1229  staff   64  6 24 23:44 marcel-0.3.2
drwxr-xr-x  2 mitsuaki1229  staff   64  6 24 23:44 mimemagic-0.3.2

再インストールが必要なGemを確認

$ gem list

*** LOCAL GEMS ***

xxx (x.x.x)

rootが混じっているので強制的に削除

※gem uninstallだと所有者がrootのGemが消えないため

gems

$ sudo rm -rf  /Users/mitsuaki1229/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/
Password:

extensions

$ sudo rm -rf /Users/mitsuaki1229/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/
Password:

doc

$ sudo rm -rf /Users/mitsuaki1229/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/doc
Password:

bundlerをインストール

$ gem install bundler
Successfully installed bundler-1.16.2
Parsing documentation for bundler-1.16.2
Done installing documentation for bundler after 4 seconds
1 gem installed

再インストールが必要なGemを再インストール

$ gem install xxx

原因

おそらく何かしらのGemをrbenv上インストールする際にsudoを付与してしまったと思うのですが、記憶が定かではないです。。

2
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
2
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?