7

I created a new rails app: rails new -d postgresql

However, I cannot get the pg gem to install. I had previously installed postgres using brew and it starts up automatically with my Mac.

I have tried several things posted here on SO. I am using ruby 2.0. When running bundle install, I get the error:

Errno::EACCES: Permission denied - /Library/Ruby/Gems/2.0.0/gems/pg-0.17.1/.gemtest

An error occurred while installing pg (0.17.1), and Bundler cannot continue.

Make sure that gem install pg -v '0.17.1' succeeds before bundling.

I tried downloading the postgresapp, but when I try to start it, there is an obvious conflict b/c it says: could not start on Port 5432. Not sure if this is causing an issue or not.

I also tried this:

sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-
config=/Users/david/Library/Application Support/Postgres/var-9.3/postgresql.conf

And got the error: Failed to build gem native extension.

I am a fairly new programmer, so please be as detailed as possible in your response. Thanks!

FIXED: I followed Justin's advice below and then did a restart. After that, I reran 'bundle install' and the pg gem finally installed!

Community
  • 1
  • 1
David
  • 652
  • 2
  • 12
  • 21
  • 1
    This might sound crazy, but you should uninstall it via homebrew, then reinstall it. `brew uninstall postgresql` then `brew update`, then `brew install postgresql`. I had similar issues awhile ago and this did the trick. – Justin Jul 06 '14 at 15:05
  • @Justin thanks for the help; unfortunately, this did not work. I am now trying to install from EnterpriseDB and see if that works. Thanks :) – David Jul 06 '14 at 15:11
  • 1
    Try to update your Xcode Tools: http://stackoverflow.com/a/19620569/2456549 – Justin Jul 06 '14 at 15:13
  • @Justin did that just now and am getting same error message above when trying to install the pg gem. thanks again – David Jul 06 '14 at 15:17
  • Are you using rvm or rbenv? You'd have to start much of your process all over if you're not, but they are worth it in my experience. – Some Guy Jul 06 '14 at 15:20
  • I have rvm installed, how do I know if I'm using it? – David Jul 06 '14 at 15:21
  • When I run psql --v, I get: "psql: FATAL: database 'david' does not exist" – David Jul 06 '14 at 15:22
  • There are a few different ways. Try running 'which ruby', and if you get something that starts with ~/.rvm/rubies, then you're using rvm. If you get something like /usr/bin/ruby, then you're not. My guts says you're not, as you shouldn't need sudo to install any gems with rvm. – Some Guy Jul 06 '14 at 15:26
  • I got /.rvm. And now it is **fixed**. Not sure how that happened, but I restarted and reran bundle install and there it is. Thank you both! – David Jul 06 '14 at 15:29
  • @Justin add as an answer, and I will mark it as the answer. :) – David Jul 06 '14 at 15:31

1 Answers1

10

First, you should update your Xcode Tools since you are on MacOS. Here is a good post on that: Installing PG gem on OS X - failure to build native extension

Then, I would go ahead and get a fresh instance of Postgres installed via Homebrew. First, uninstall it

brew uninstall postgresql

I would say run brew update, but the link I mentioned has you updating Homebrew. Now reinstall postgres with

brew install postgresql
Justin
  • 4,922
  • 2
  • 27
  • 69