Installing gem or updating RubyGems fails with per

2019-01-01 11:48发布

Trying to install a gem (gem install mygem) or update RubyGems (gem update --system) fails with this error:

ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

Anyone having idea how to solve this?

23条回答
路过你的时光
2楼-- · 2019-01-01 12:04

The reason of the error is because you are not logged in as the root user on terminal.

If you already have root use enable on your mac in terminal type

$ su

If you dont have root user, you need to enable it using the following steps

  1. From the Apple menu choose System Preferences….
  2. From the View menu choose Users & Groups.
  3. Click the lock and authenticate as an administrator account.
  4. Click Login Options….
  5. Click the “Edit…” or “Join…” button at the bottom right.
  6. Click the “Open Directory Utility…” button.
  7. Click the lock in the Directory Utility window.
  8. Enter an administrator account name and password, then click OK.
  9. Choose Enable Root User from the Edit menu.
  10. Enter the root password you wish to use in both the Password and Verify fields, then click OK.

More at the same on http://support.apple.com/kb/ht1528

Atleast it works for me after getting stuck for couple of hours.

查看更多
柔情千种
3楼-- · 2019-01-01 12:08

Work for me:

sudo gem uninstall cocoapods

sudo gem install cocoapods
查看更多
柔情千种
4楼-- · 2019-01-01 12:11
sudo gem update --system
sudo gem install (gemfile)
查看更多
爱死公子算了
5楼-- · 2019-01-01 12:13

Try nathanwhy's answer before using my original answer below. His recommendation of --user-install should accomplish the same purpose without having to muck with your .bash_profile or determine your ruby version.


If you are not concerned about a specific ruby version, you can skip the heavy-lift ruby environment manager options, and just add these lines to ~/.bash_profile:

export GEM_HOME="$HOME/.gem/ruby/2.0.0"
export GEM_PATH="$HOME/.gem/ruby/2.0.0"

The path is stolen from the original output of gem env:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.0.14
  - RUBY VERSION: 2.0.0
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
  - RUBY EXECUTABLE: /System/Library/.../2.0/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-14
  - GEM PATHS:
     - /Library/Ruby/Gems/2.0.0
     - /Users/mylogin/.gem/ruby/2.0.0 # <-- This guy, right here.
     - /System/Library/.../usr/lib/ruby/gems/2.0.0
  ...

No sudoing is required, and you can use the already-installed ruby, courtesy of Apple.

查看更多
泪湿衣
6楼-- · 2019-01-01 12:13

I used this and worked.

$ sudo chown myuser /var/lib/gems

查看更多
谁念西风独自凉
7楼-- · 2019-01-01 12:14

Try adding --user-install instead of using sudo:

gem install mygem --user-install
查看更多
登录 后发表回答