3

I've installed PostgreSQL using Brew (having previously tried to install using the standalone installer found on the PostgreSQL website), but am receiving the following error message when I try to bundle install:

Errno::EACCES: Permission denied - /Users/xxxxx/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.1/.gemtest An error occurred while installing pg (0.14.1), and Bundler cannot continue. Make sure that `gem install pg -v '0.14.1'` succeeds before bundling.

I've found various potential solutions on Stackoverflow, none of which appear to fix the issue.

psql --version returns: 9.2.1 which psql returns: /usr/local/bin/psql

Anyone recognise this error, and/or have any further ideas as to how to fix it?

Failing that, I suppose I could stick with SQLite locally, and use PostgreSQL in the production environment. I assume I would need to manually make the following changes to the database.yml file (I'm about to deploy for the very first time):

production:
  adapter: postgresql
  encoding: unicode
  database: myapp_production
  pool: 5
  username: myapp
  password: 

And, in my gemfile, include the following (note that running bundle install returns the same error, but because I'm assuming there won't be any errors with the PostgreSQL installation on the production server, I think it should still work?):

group :production do

  gem 'pg'

end

EDIT: Scratch that, Webrick won't run at all if gem 'pg' is included in the gemfile.

EDIT 2: Also, when I try to run rvmsudo gem install pg, I get this:

ld: in /usr/local/lib/libssl.0.9.8.dylib, missing required architecture x86_64 in file
collect2: ld returned 1 exit status
make: *** [pg_ext.bundle] Error 1

** EDIT 3: ** Admitting defeat.

Hi folks,

Firstly, thanks for all your help.

Unfortunately, after two days, I'm going to have to admit defeat.

No matter which method I try, and whether I use the EnterpriseDB version or Homebrew-installed version of PostgreSQL, I simply cannot install the pg gem. I've tried all of the following:

install gem pg

sudo install gem pg

rvmsudo install gem pg

sudo env PATH=/library/PostgreSQL/9.2/bin:$PATH gem install pg (when using the EnterpriseDB installer)

rvmsudo env PATH=/library/PostgreSQL/9.2/bin:$PATH gem install pg (ditto)

rvmsudo env PATH=/library/PostgreSQL/9.2/bin:$PATH ARCHFLAGS="-arch x86_54" gem install

Whichever of the above methods I choose returns the following error:

ld: in /usr/local/lib/libssl.0.9.8.dylib, missing required architecture x86_64 in file

Whenever I try to install the gem via a bundle install, I get the following error:

Errno::EACCES: Permission denied - /Users/xxx/.rvm/gems/ruby-1.9.3-p194/gems/pg-0.14.1/.gemtest
An error occurred while installing pg (0.14.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.14.1'` succeeds before bundling.

I can't afford to spend more time on this, so I've bit the bullet and will probably use MySQL instead.

Thanks again,

Graeme

FINAL EDIT - Fixed! See my answer below for how I did it, as it may help others **

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
Graeme
  • 481
  • 6
  • 20
  • "previously tried to install using the standalone installer found on the PostgreSQL website". What happened with that? Why "tried to"? Did you uninstall? What problem(s) did you encounter? – Craig Ringer Oct 08 '12 at 20:38
  • Hi, I used brew uninstall postgresql --force to uninstall older versions before installing the "Brew" version. However, I didn't reboot, which may have resulted in some "leftovers" - so, after rebooting, I'm going to try uninstalling the most recent version and try again. – Graeme Oct 08 '12 at 20:55
  • and what went wrong with the official Pg installer? – Craig Ringer Oct 08 '12 at 20:59
  • Postgres.app is one of the solutions linked to from the official Postgres Downloads page, so you may have already tried it. But check it out if you haven't: http://postgresapp.com/. Works for me while Homebrew did not (perhaps the same problem, but I don't remember). – danneu Oct 08 '12 at 21:07
  • 1
    Finally, don't use SQLite locally if you're using Postgres in production. Use Postgres on both sides. There are too many differences and too much headache. You'll find that things will work locally in SQLite, but in production Postgres you'll find that various Active Record queries won't work anymore. For instance, SQLite is much less picky about the GROUP BY clause matching up with your SELECT statement. – danneu Oct 08 '12 at 21:10
  • This is where I feel a bit silly. Probably nothing - being a noob, I immediately uninstalled it when I saw a Railscast suggesting I use Brew to install it. Unfortunately, I'm still getting the same error: "Building native extensions. This could take a while... ERROR: Error installing pg: ERROR: Failed to build gem native extension. /Users/xxx/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb" – Graeme Oct 08 '12 at 21:10
  • @danneu Unfortunately, that app only works on Lion (see https://github.com/mattt/PostgresApp/issues/24) – Graeme Oct 08 '12 at 21:19
  • psql is just a client and comes with OSX, so that part is not relevant. – Dondi Michael Stroma Oct 08 '12 at 22:52
  • @Graeme is that the same error? Your initial error suggested a permissions issue, perhaps corrupt permissions on unpacking the gem? The second error you posted above in the comments seems different. – Chris Travers Oct 09 '12 at 01:17
  • @ChrisTravers No, these are different errors which occur at different stages of installation. PostgreSQL seems to install OK via Homebrew, but the gem refuses to install. – Graeme Oct 09 '12 at 09:28

3 Answers3

6

YES!!!!

Sorry, but I think I might leap into the air. I think I may have got it to work.

In case anyone else runs into this problem, here's what I did to get the gem to install on Snow Leopard (the process may be different for Lion):

1) Make sure you uninstall any old versions of PostgreSQL - both EnterpriseDB & Homebrew versions. For EnterpriseDB, see this Stackoverflow question/answer, and for Homebrew, simply do brew uninstall postgresql --force.

2) Do a brew install postgresql to get the Homebrew installation.

3) Now, the problem (as Chris Travers pointed out in an earlier comment - Thanks Chris!) appears to be due to OpenSSL. It seems my version (which I guess was Snow Leopard's default version, as I'd never heard of it til today) was an older version, so I had to use Homebrew to install a more up-to-date version (I also used MacPorts to uninstall the old version - not sure it's appropriate having MacPorts and Homebrew installed on the same computer, but...):

  1. Macports: sudo port uninstall openssl
  2. Homebrew: brew install openssl

This should update OpenSSL to the latest 64-bit version (I think?).

4) Following on from another Stackoverflow post, I did the following:

sudo gem install pg -- --with-ldflags='-L/usr/local/Cellar/openssl/0.9.8s' 

Success! That seemed to work. I've still to set up a new Rails project to check everything installed OK, but bundle install causes no problems when gem 'pg' is included in my Gemfile, so fingers crossed :-)

Hope this helps others.

Community
  • 1
  • 1
Graeme
  • 481
  • 6
  • 20
  • wonderful. you should have hundreds of upvotes for this. I am pretty sure anyone with a mac trying to use heroku is running into this problem. – Jesse Black Dec 04 '12 at 18:33
1

It looks to me like you are missing something regarding OpenSSL (whether a header file or otherwise) on your installation. I would double check the installation there. Failing that I would suggest looking into disabling SSL support on this gem however you do that. I looked over the source and it looks like it compiles against libpq which may already be able to link to OpenSSL anyway so that may not be an issue.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
  • I'm not sure if I've installed OpenSSL, or even if OpenSSL is already installed by default, on my system (I'm very much a noob). Given that most other gems install correctly, this might not be the cause, but it's worth looking into. – Graeme Oct 09 '12 at 12:04
  • 1
    It looks to me like a linking issue, not finding a 64-bit version of openssl's library file. It could also be a path issue. You might search for openssl and see if you can determine if you have all the right versions installed in the right places. – Chris Travers Oct 09 '12 at 12:06
  • I updated OpenSSL to 1.0.01c running on darwin64-x86_64-cc through MacPorts. Still no luck though. Will see if it's a paths issue, otherwise I think I'm defeated, and possibly the owner of a borked Mac... – Graeme Oct 09 '12 at 15:26
  • I've accepted your answer as, while I had to poke around a bit to find the solution, it was a great starting point for me. Cheers! – Graeme Oct 09 '12 at 17:14
0

Here's what worked for me:

1) installing postgres gem from my console

brew install postgres
sudo env ARCHFLAGS="-arch x86_64" gem install pg

2) Then afterwards in my GemFile so I could continue to use sqlite for dev:

group :development, :test do
   gem 'sqlite3'
end
group :production do
  gem 'pg'
end
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
Bill
  • 1