Cannot install PG gem on Mac OSX

macos, postgresql, ruby, ruby-on-rails, rubygems

Solution

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

Problem

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!

Original source

Related problems