34

I am trying to install create a new app in Ruby on Rails and I cannot get passed this error:

$ gem install pg

ERROR: While executing gem ... (Errno::EACCES) Permission denied @ rb_sysopen - /Users/stormyramsey/.rbenv/versions/2.3.2/lib/ruby/gems/2.3.0/gems/pg-0.21.0/.gemtest

3
  • Try with sudo gem install pg. Commented Jun 27, 2017 at 1:07
  • 1
    @SebastiánPalma: sudo ought to be unnecessary if the goal is to install the gem under ~/.rbenv. Unless I'm missing something. Commented Jun 27, 2017 at 2:58
  • @StormyRamsey, Who owns /stormyramsey/.rbenv/? Is it the root user? Commented Jun 27, 2017 at 3:53

9 Answers 9

64

Its a permissions issue. You could fix it with this:

sudo chown -R $(whoami) /Library/Ruby/Gems/*

or possibly in your case

sudo chown -R $(whoami) /Users/stormyramsey/.rbenv/versions/2.3.2/lib/ruby/gems/*

What does this do:

This is telling the system to change the files to change the ownership to the current user. Something must have gotten messed up when something got installed. Usually this is because there are multiple accounts or users are using sudo to install when they should not always have to.

Sign up to request clarification or add additional context in comments.

3 Comments

could you explain what exactly is the issue?
Updated my answer with the explanation
sudo chown -R $(whoami) "MY_PATH" works for me
15

No need to change permission, just export GEM_HOME:

export GEM_HOME="$HOME/.gem"

1 Comment

@Stormy Ramsey, please, if you agree, this answer should be labeled as the one that solved the issue.
10

It's likely there's a permissions problem somewhere along the .rbenv path. You might try turning on write privileges for your user with:

$ chmod -R +w ~/.rbenv

That will recursively (-R) change the file mode (chmod) to write permission (+w) for all files and directories under your user's .rbenv path. There's no particular reason for not having files set to write.

Comments

5

For Mac M1 systems try,

  1. Allowing full disk access to terminal.

    Apple->systemPreferences->Security&Privacy->privacy(Tab)->'+' button, check in Terminal application. Then Restart terminal 2.Try using,

    sudo chflags noschg

1 Comment

Thanks. PS - You forgot after the privacy(tab) to click Full Disk Access on the left
1

Delete the pod folder, reinstall it again. If it doesn't work use this command:

sudo pod install --allow-root

2 Comments

This flag is very risky, avoid at all cost.
leads to a lot problems
0

It really doesn't matter on mac how you configure your eyaml create the dir and config manually, add some public key location to it, and its works just fine after adding full disk access to the terminal as Kewin suggested ^ ^. Thumbs up.

Comments

0
  1. pod install
  2. you got error Errno::EACCES - Permission denied @ rb_sysopen and here some path to denied file
  3. do sudo chown -R whoami /Users/<your username>/Library/Caches/CocoaPods/Pods set the path that you have in your error
  4. pod install
  5. you got another error again
  6. go to step 2

Possible errors:

1)Errno::EACCES - Permission denied @ rb_sysopen - /Users/<your username>/Library/Caches/CocoaPods/Pods/External/DoubleConversion/77f51e588bfe0e5c4fa6e9c580da62c6-76ab8.lock

  1. Errno::EACCES - Permission denied @ rb_sysopen - /Users/<your username>/Library/Caches/CocoaPods/Pods/VERSION

Comments

-1

please run:

sudo gem install pg

Comments

-1

sudo chmod 777 file_name (because of superuser) previlage accepted

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.