简体   繁体   中英

error occurred while installing pg (0.17.1)

When I run a bundle on a rails project I seem to be getting the following:

Installing pg 0.17.1 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r 

./siteconf20151024-43303-t81fnp.rb extconf.rb checking for pg_config... yes Using config values from /usr/local/bin/pg_config 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 have visited the following SO questions:

Additionally to this I've tried executing the following:

gem install pg

env ARCHFLAGS="-arch x86_64" gem install pg

gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.4.5/bin/pg_config

And I keep getting:

ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

FYI I have rbenv installed too. Also tried a rbenv rehash also and executed the above commands and have had no luck. I've also tried uninstalling and reinstalling Postgres and get the same. To also be on the safe side i've also ran:

  • brew update
  • brew uinstall posgresql > brew install postgresql
  • updated Xcode

Info:

  • Mac OSx Yosemite 10.10.5
  • Postgres v9.4.5
  • rbenv v0.4.0
  • rbenv global => 2.0.0-p247

I don't know Mac, but I've had this problem on Windows.

--

The issue is here:

Failed to build gem native extension

When you install a gem, many of the advanced ones actually compile / "build" through the extconf.rb file. I've forgotten the significance of this, but it basically allows the gem to run natively on the OS environment you're using.

In short, the error occurs because your OS does not have access to the "developer headers" the gem requires to compile.

The most common instance of this problem is with the mysql2 gem on Windows , but happens for others too.

--

What you need is to download PGSQL on your system before attempting to install the gem.

After installing PGSQL, you may need to reference the developer headers with some "switches", but it does not appear to be the case in this instance:

Installing PG gem on OS X - failure to build native extension

  1. Install Xcode command line tools (Apple Developer site)
  2. brew uninstall postgresql
  3. brew install postgresql
  4. ARCHFLAGS="-arch x86_64" gem install pg

Maybe this won't work? I don't know... I know that in Windows, you have to install the binaries before expecting the gem to work.

Greetings I hope I can help. May I ask how you created your rails project? Did you simply use:

rails new *appname*

If so maybe try creating a new rails app like so:

rails new *appname* -d postgresql

And before you create your database and run migrations/seed, you should go into "config/database.yml" and change the username and password to the postgreSQL user that you've hopefully setup after installing postgreSQL on your machine.

Good Luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM