gem install pg doesn't work on OSX Lion

南楼画角 提交于 2019-11-28 03:29:01

I finally found the cause of the problem! Though I am still uncertain how this problem came about.

Look at the contents of the mkmf.log file that is created when my install command fails (see my original post). It logs an attempt to run the following command

/usr/bin/gcc-4.2 ...and so on...

There is no /usr/bin/gcc-4.2 on my system. There is a gcc, which is symbolically linked to llvm-gcc-4.2. My solution was to create another symbolic link

sudo ln -s llvm-gcc-4.2 gcc-4.2 

After making this link, my gem install pg command worked without any problems.

I found the solution to this problem on the Frozen Canuck blog in the post Error Installing Ruby Gem with C Extension. He speculates that the problem can be caused by conflicting versions of XCode. whatever the cause, my eternal thanks!

On OS X Mavericks

sudo ln -s /usr/bin/llvm-gcc /usr/bin/gcc-4.2

works.

spirossi

I had a similar issue. Following an answer by bobfet1 for a similar issue I was able to get the gem installed by:

sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config

Thanks to this guy: http://www.computersnyou.com/2025/

On Mavericks using: xcode-select --install (assuming you have installed Xcode from the app store) works.

Installing xcode from the app store is not enough. You will also need xcode's command line tools. https://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_4_3.html

After installing xcode from the app store, open xcode. Goto Xcode->Open Developer Tool->More Developer Tools Download and install the latest command line tools.

Open a terminal window and run: sudo gem install pg

Similar problem on Mavericks 10.9 -- but it was caused by not having agreed to the Xcode license agreement. Blech.

Run sudo xcodebuild and agree to the junk. The everything works as expected.

I also ran into this issue, for me the answer was updating RVM of all things.

rvm get head
rvm install 1.9.2

I too, am on Mountain Lion, besides the "sudo ln -s /usr/bin/{llvm-,}gcc-4.2" suggested by @grilix, I needed to do:

sudo ln -s /usr/bin/{llvm-,}g++-4.2

After a Mavericks upgrade...

Reinstall your ruby version.

rvm uninstall 1.9.2-p320

then

rvm install 1.9.2-p320

or whatever version of ruby you have.

I am on Mountain Lion, and the accepted answer from Dave Isaacs worked for me. I also had to do

sudo ln -s llvm-g++-4.2 g++-4.2
Rick Colosimo

Rather than updating RVM itself (https://stackoverflow.com/a/10430742/2807795), as above, it was the reinstallation of Ruby 2.0.0-p247 that did the trick, after trying all the other steps above without success.

rvm get head
rvm install 2.0.0
Naveen Segaran
$ gem install pg

If that failed:

$ sudo gem install pg

Then, if that failed:

$ sudo find / -name “pg_config”

After you find pg_config's location, run this to finally install it:

$ sudo gem install pg --with-pg-config=/usr/local/Cellar/postgresql/9.5.1/bin/pg_config

Of course, you'll want to change the path to wherever you found pg_config.

Then, check your installed gems with gem list, and it should show something like this:

More information can be found in my guide.

If the output includes:

/Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': \
    The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.

then there really is something amiss with your compilation environment. Especially when the failure is the very first test that extconf.rb runs.

If you have XCode installed, then perhaps you don't have the command-line tools component of XCode installed? They were recently split out from XCode proper, so you need to install them separately.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!