Can't install pg gem on Mountain Lion - ruby-on-rails

I have been having a lot of troubles with Rails after upgrading to Mountain Lion.
Trying to trouble shoot these and searching for hours on the internet so far I have done the following to ensure my system has all the dependencies to run rails after the upgrade:
I updated my Homebrew installation
I updated my RVM installation
I installed the XCode command line tools
I installed GCC as mentioned
I upgraded my version of Ruby to
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
My Rails version is verified as Rails 3.2.6
I also found out that Mountain Lion has some issues with Postgres so I saw this post and found out that I need to add this line to my Bash profile:
export PATH="/usr/local/bin:/usr/bin:$PATH"
Now I go to my Rails app that used to run fine on Snow Leopard before I upgraded, and when I run rails s at the command line I get the following error:
AM#~/Documents/RailsWS/app0815 >gem install pg
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/AM/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/AM/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
/Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:368:in `try_do':
The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
from /Users/AM/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
from extconf.rb:41:in `<main>'
Gem files will remain installed in /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.14.1 for inspection.
Results logged to /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/pg-0.14.1/ext/gem_make.out
When I go to the Rails app and try bundle install it fails at pg installation.

Download the postgresSQL installer from http://www.enterprisedb.com/products-services-training/pgdownload#osx
and then make your path look something like this:
PATH=$PATH:/Library/PostgreSQL/9.0/bin/ gem install pg
This would do!
Note: Please specify your postgreSQL installed version correctly in the path.
UPDATE(10/11/2015) (Taken from Heroku)
On OS X with Homebrew:
Install postgresql using:
brew install postgresql
Then install the gem using:
gem install pg -- --with-pg-config=/usr/local/bin/pg_config
On OS X with MacPorts:
gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
Hope this helps!

As banditKing says in his answer, need to tell the gem where to find the postgres binaries. You can use the binaries included with the excellent and easy postgres.app from Heroku ( http://postgresapp.com ) to install this gem instead of the EnterpriseDb version. The EnterpriseDB version is great, but an involved install for a dev machine.
Download Postgres.app on your system and add the internal bin directory to your path. I put it in /Applications/Postgres.app, so I used
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
worked for me on 10.8.2, Ruby 1.9.3, pg-0.14.1, and the XCode CLI tools

Alternatively, use the Postgres app. IMO, it's the easiest and fastest way to get up and running with PostgreSQL and Rails on Mac.
For detailed instructions: http://blog.parsalabs.com/blog/2013/09/14/installing-postgresql-don-mac-os-x-and-using-it-as-your-rails-apps-database/

After installing Mavericks bundle update was throwing an error on the pg gem.
I use Brew to manage my packages and postgresql was already installed, but still I was getting the 'no pg_config' error.
The fix was to just brew uninstall postgresql, then brew install postgresql. After which I was immediately able to successfully run bundle update.

Related

rails 5.0.0 when installing "nio4r" : Failed to build gem native extension

Here is the logs: http://pastebin.com/CAgur9xd
Installing nio4r 1.2.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
C:/RailsInstaller/Ruby2.2.0/bin/ruby.exe -r ./siteconf20160720-8272-c88sgk.rb extconf.rb --with-cflags=-std=c99
checking for unistd.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/RailsInstaller/Ruby2.2.0/bin/$(RUBY_BASE_NAME)
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:587:in `try_cpp'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1060:in `block in have_header'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:347:in `postpone'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1059:in `have_header'
from extconf.rb:3:in `<main>'
extconf failed, exit code 1
when installing bundle it returns(starts at line 117 in the logs ):
Installing nio4r 1.2.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
So the bundle can't be installed. It returns at the end :
An error occurred while installing nio4r (1.2.1), and Bundler cannot continue.
Make sure that `gem install nio4r -v '1.2.1'` succeeds before bundling.
Note :I have tried the solutions in other questions, but it is still the same.
If it is possible to install "nio4r" manually please tell me how .
I am facing the same issue while I was trying to upgrade my Rails to V5.0.0, I follow this instruction and it works perfectly. Read the section "Install the Ruby DevKit" here >> http://jekyll-windows.juthilo.com/1-ruby-and-devkit/
Solution for Fedora 64bit
sudo dnf install redhat-rpm-config
I had a similar problem and running this command solved my issue.
bundle config build.nio4r --with-cflags="-std=c99"
Now you can successfully run bundle install afterwards.
I came across this problem as i was setting up rails too. (looking for an alternative to php).
I realized that i had installed x86 ruby with x64 Devkit, so i first downloaded x64 ruby which i installed and uninstalled the x86 version. I made sure my path variables were well set.
Then i installed devkit using the instructions on this page http://rubyonwindowsguides.github.io/book/ch02-04.html
Finally i installed rails and it worked fine without the errors this time
Hope this helps
My son fixed this problem for me. The problem was that I installed first, Ruby and then the Rails installer. So I had to uninstall Ruby and reinstall with the Rails installer only.
Had this same issue on Ubuntu 16.04.
What I did to fix this :
Remove Gemfile.lock : sudo rm Gemfile.lock
Installed Ruby-Dev:
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt-get update
sudo apt-get install ruby2.4-dev
and the important step : REBOOT!
this may be related: GCC compilation error when installing Nokogiri
I found a error. i had a 2 gcc versions installed on my system and I just run brew unlink gcc and that solved the problem.
this was my case too. benw unlink gcc worked
Remove the Gemfile.lock and run bundle install command
To quote from your log output:
The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
On windows, you need to install the DevKit in order to be able to compile gems.
If you use Windows and installed ruby with RubyInstaller with version more or equal to 2.4, than you should not install DevKit from RubyInstaller website and only use 'msys64' which is installed after Ruby with RubyInstaller (make sure you type number 3 to install both msys and mingw). Delete devkit directory and its path from PATH environment variable, so when rubygems will try to install nio4r and call C compilers, it will call msys ones.
Read here https://rubyinstaller.org/2017/05/25/rubyinstaller-2.4.1-1-released.html for more info about MSYS2 and DevKit in RubyInstaller

Error building native extensions prevents non-sudo command working

I'm upgrading an existing setup to use Rails 5 beta 3. As part of that, I've upgraded Ruby to version 2.2.4 (using RVM), i.e.
rvm install 2.2.4
rvm use 2.2.4
With that done, I'm trying to install the Rails gem. However, running
sudo gem install rails
gives me the error
ERROR: Error installing mime-types-data: mime-types-data requires Ruby version >= 2.0.
Having read this question, I've looked at my Ruby versions:
ruby --version => ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
sudo ruby --version => ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
I don't seem to be able to access RVM from sudo, so I tried using gem install rails instead, which also fails while building native extensions:
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/home/ubuntu/.rvm/rubies/ruby-2.2.4/bin/ruby -r ./siteconf20160405-31973-l7bzq7.rb extconf.rb
checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/ubuntu/.rvm/rubies/ruby-2.2.4/bin/$(RUBY_BASE_NAME)
--help
--clean
/home/ubuntu/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /home/ubuntu/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:571:in `block in try_compile'
from /home/ubuntu/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:522:in `with_werror'
from /home/ubuntu/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:571:in `try_compile'
from extconf.rb:80:in `nokogiri_try_compile'
from extconf.rb:87:in `block in add_cflags'
from /home/ubuntu/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:619:in `with_cflags'
from extconf.rb:86:in `add_cflags'
from extconf.rb:336:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /home/ubuntu/.rvm/gems/ruby-2.2.4/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /home/ubuntu/.rvm/gems/ruby-2.2.4/extensions/x86_64-linux/2.2.0/nokogiri-1.6.7.2/gem_make.out
I see two solutions to this:
Upgrade the Ruby that's used in sudo commands to 2.0 or above (preferably 2.2.4). I can't figure out how to do this, because sudo rvm results in command not found for rvm.
Fix the error that comes up when using gem install rails. Again, I don't know how to do this.
Which of these is the easiest (or is there an easier fix), and how do I do it?
It looks like you have installed RVM in single user mode. This is the reason why sudo rvm returns command not found error. You can find more about RVM modes here: https://rvm.io/rvm/install#2-load-rvm-into-your-shell-sessions-as-a-function.
But, based on log your provided, the error is in installing Nokogiri. Please install development header files first with command sudo apt-get install ruby-dev zlib1g-dev liblzma-dev. For details follow: http://www.nokogiri.org/tutorials/installing_nokogiri.html
The sudo command that you invoke will be executed as the root user, hence it won't load your profile settings (which is where the rvm ruby version is loaded, if it works like rbenv which is what I use, never used rvm)
On the other hand, whenever a Building native extensions fail when installing a gem it means that you need the development packages (C/C++ header files) for a library that is the one that actually does the whole thing (ruby gems are usually wrappers around it), so for instance, if you want to build ruby you will need the ruby development package from your linux distribution (or from brew if you use OSX), the development package from postgres to build pg gem, etc.

Failure to build native extension

I am new to rails and attempting to switch my default DB to Postgres from SQLite3. I have encountered an error. I am using gem install pg and getting this error error: Error installing pg: ERROR: Failed to build gem native extension. I am using Mavericks OSX and Ruby 1.9.3, Rails 3.2.12, and PG 9.3 –The goal is to deploy a sample app to heroku (which doesnt seem to support SQLite.
Steps I have tried:
link 1: Installing PG gem on OS X - failure to build native extension
link 2(heroku instructions): https://devcenter.heroku.com/articles/sqlite3
EDITED TO INCLUDE SPECIFIC ERROR MESSAGE BELOW:
HEAD https://rubygems.org/latest_specs.4.8.gz
302 Moved Temporarily
HEAD https://s3.amazonaws.com/production.s3.rubygems.org/latest_specs.4.8.gz
304 Not Modified
HEAD https://rubygems.org/specs.4.8.gz
302 Moved Temporarily
HEAD https://s3.amazonaws.com/production.s3.rubygems.org/specs.4.8.gz
304 Not Modified
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/.gemtest
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/BSDL
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ChangeLog
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/Contributors.rdoc
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/History.rdoc
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/LICENSE
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/Manifest.txt
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/POSTGRES
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/README-OS_X.rdoc
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/README-Windows.rdoc
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/README.ja.rdoc
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/README.rdoc
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/Rakefile
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/Rakefile.cross
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/errorcodes.def
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/errorcodes.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/errorcodes.txt
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/extconf.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/gvl_wrappers.c
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/gvl_wrappers.h
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/pg.c
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/pg.h
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/pg_connection.c
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/pg_errors.c
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/pg_result.c
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/vc/pg.sln
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/vc/pg_18/pg.vcproj
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/ext/vc/pg_19/pg_19.vcproj
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/lib/pg.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/lib/pg/connection.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/lib/pg/constants.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/lib/pg/exceptions.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/lib/pg/result.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/array_insert.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/async_api.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/async_copyto.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/async_mixed.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/check_conn.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/copyfrom.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/copyto.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/cursor.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/disk_usage_report.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/issue-119.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/losample.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/minimal-testcase.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/notify_wait.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/pg_statistics.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/replication_monitor.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/test_binary_values.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/wal_shipper.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/sample/warehouse_partitions.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/data/expected_trace.out
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/data/random_binary_data
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/lib/helpers.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/pg/connection_spec.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/pg/result_spec.rb
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.0/spec/pg_spec.rb
Building native extensions. This could take a while...
/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/local/bin/pg_config
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby
--with-pg
--without-pg
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
/usr/local/rvm/rubies/ruby-1.9.3-p392/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.
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:461:in `try_link0'
from /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/mkmf.rb:476:in `try_link'
from extconf.rb:39:in `<main>'
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
Building has failed. See above output for more information on the failure.
Gem files will remain installed in /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/gems/1.9.1/gems/pg-0.17.0 for inspection.
Results logged to /usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/gems/1.9.1/gems/pg-0.17.0/ext/gem_make.out
It's trying to build the gem pg, which has C or C++ code in it, and the compilation phase is not working. Under OS X, you must install XCode or get a compiler by other means, and the shell you're using to run bundle install must have the compiler in its path. I've compiled pg many times under OS X, though I have not upgraded to Mavericks.
If you have XCode installed, the above paragraph doesn't apply. You'll get additional information on what's going wrong if you try gem install pg. Try that and post the results.
The key is "You have to install development tools first." This is a strong hint that you don't have a proper compiler. This page says XCode must be v5.01 or later.
Thanks all for your help. The specific issue was resolved by me running the below command in terminal
brew install apple-gcc42
To clarify, I had the most recent XCode (with command line) and Mavericks, Ruby 1.9.3, Rails 3.2.12, and PG 9.3. I am unsure why that specific command worked when I already had the command line tools installed. The one change of the output of
gcc--version
was that --prefix=/Library/Developer/CommandLineTools/usr
changes to
--prefix=/Applications/Xcode.app/Contents/Developer/usr
Again, this change worked in practice, but I am not sure why this fixed things.

Install Rails Failed on OSX 10.8.4

I always failed to install rails on my new Air with OSX 10.8.4, even I succeed installed ruby2, Command Line Tool of XCode, it still prompts some error when I try to install rails.
I found lots solutions from the Internet, but they all don't work on my issue, I'm completely confused, doesn't any can help me? I'll really appreciate!!!
localhost:myapp zerocool$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]
localhost:myapp zerocool$ sudo gem install rails
Password:
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/Users/zerocool/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/zerocool/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
--with-atomic_reference-dir
--without-atomic_reference-dir
--with-atomic_reference-include
--without-atomic_reference-include=${atomic_reference-dir}/include
--with-atomic_reference-lib
--without-atomic_reference-lib=${atomic_reference-dir}/
/Users/zerocool/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:434:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/zerocool/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:519:in `try_link0'
from /Users/zerocool/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:817:in `try_run'
from extconf.rb:24:in `<main>'
Gem files will remain installed in /Users/zerocool/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/atomic-1.1.12 for inspection.
Results logged to /Users/zerocool/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/atomic-1.1.12/ext/gem_make.out
I ran into this issue today and it seems that my download of ruby-2.0.0 did not work properly. I would recommend trying rvm reinstall 2.0.0 followed by gem install rails.
Finally, I got the solution! Run rvm implode,and use rm to delete /etc/rvmrc and ~/.rmvrc, restart your mac, and you can use gem install rails to install rails successfully.
First I installed gcc via homebrew:
installing gcc on mavericks using brew
brew tap homebrew/dupes
brew install apple-gcc42
Then I symlinked the newly installed apple-gcc42
into my /usr/bin folder
cd /usr/bin
sudo mv gcc gcc_mavs sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 gcc
Credits: https://coderwall.com/p/lqpp8w
I had this same error when running against ruby-2.0.0-p195, but updating to ruby-2.0.0-p247 (the current RVM default for 2.0.0) fixed it.

OSX Lion - can't install Postgres gem

I am not sure what happened - I know Postgres was working right after the upgrade to Lion, but it is not working anymore. I have Xcode 4 installed.
error:
$ gem install pg -- --with-pg-config=/usr/bin/pg_config
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/Users/Me/.rvm/rubies/ruby-1.9.2-p318/bin/ruby extconf.rb --with-pg-config=/usr/bin/pg_config
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/Me/.rvm/rubies/ruby-1.9.2-p318/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
/Users/Me/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/Me/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
from /Users/Me/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
from /Users/Me/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
from /Users/Me/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
from /Users/Me/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/Me/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
from /Users/Me/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/Me/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
from /Users/Me/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
from /Users/Me/.rvm/rubies/ruby-1.9.2-p318/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
from extconf.rb:40:in `<main>'
Gem files will remain installed in /Users/Me/.rvm/gems/ruby-1.9.2-p318/gems/pg-0.13.2 for inspection.
Results logged to /Users/Me/.rvm/gems/ruby-1.9.2-p318/gems/pg-0.13.2/ext/gem_make.out
EDIT*** I tried installing postgres via homebrew and got the following errors:
Warning: You have no /usr/bin/cc.
This means you probably can't build *anything*. You need to install the Command
Line Tools for Xcode. You can either download this from http://connect.apple.com
or install them from inside Xcode's Download preferences. Homebrew does not
require all of Xcode! You only need the Command Line Tools package!
Warning: Setting DYLD_LIBRARY_PATH can break dynamic linking.
You should probably unset it.
Warning: Your Homebrew is outdated
You haven't updated for at least 24 hours, this is a long time in brewland!
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libruby.1.8.7.dylib
Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected static libraries:
/usr/local/lib/libruby-static.a
Warning: Your compilers are different from the standard versions for your Xcode.
If you have Xcode 4.3 or newer, you should install the Command Line Tools for
Xcode from within Xcode's Download preferences.
Otherwise, you should reinstall Xcode.
Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:
bundle
edit_json.rb
erb
erubis
gem
irb
prettify_json.rb
rails
rake
rake2thor
rdoc
ri
ruby
testrb
thor
tt
update_rubygems
Consider amending your PATH so that /usr/local/bin
is ahead of /usr/bin in your PATH.
Warning: Your Xcode is configured with an invalid path.
You should change it to the correct path. Please note that there is no correct
path at this time if you have *only* installed the Command Line Tools for Xcode.
If your Xcode is pre-4.3 or you installed the whole of Xcode 4.3 then one of
these is (probably) what you want:
sudo xcode-select -switch /Developer
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Trying forcing pg gem to build with the 64 bit libpg version.
ARCHFLAGS='-arch x86_64' gem install pg
Check out the following blog post: Using MySQL and Postgres on Mac OS X (Tiger) with RoR

Resources