26

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

Sebastián Palma
  • 32,692
  • 6
  • 40
  • 59
Stormy Ramsey
  • 271
  • 1
  • 3
  • 5

7 Answers7

53

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.

Bryan Norden
  • 2,397
  • 18
  • 22
9

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.

Kathryn
  • 1,557
  • 8
  • 12
7

No need to change permission, just export GEM_HOME:

export GEM_HOME="$HOME/.gem"
DevB2F
  • 4,674
  • 4
  • 36
  • 60
  • @Stormy Ramsey, please, if you agree, this answer should be labeled as the one that solved the issue. – aerijman Aug 15 '23 at 02:08
2

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

sudo pod install --allow-root
S.B
  • 13,077
  • 10
  • 22
  • 49
2

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

Kewin V
  • 419
  • 3
  • 2
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.

-1

please run:

sudo gem install pg
gshoanganh
  • 137
  • 1
  • 3