Trying to install pg gem fails during ruby project build - ruby

I'm attempting to build a ruby project which uses postgres running locally. Build fails on the pg gem install. I get this error
$ gem install pg -v '0.12.2'
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/path/to/.rvm/rubies/ruby-1.9.3-p545/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
so... I pass the pg_config path, and get a different error:
$ gem install pg --with-pg-config=/usr/pgsql-9.2/bin/pg_config -v '0.12.2'
ERROR: While executing gem ... (OptionParser::InvalidOption)
invalid option: --with-pg-config=/usr/pgsql-9.2/bin/pg_config
Very confused.

Make sure you have libpq-dev package installed. If you don't, install it and try installing pg again without the --with-pg-config parameter.
In regards to the --with-pg-config parameter:
When passing parameters to the gem you're installing you must use two dashes before the two dashes from the option, like so:
gem install gem-name -- --gem-option
So what you want to run in order to achieve installing pg with the --with-pg-config option is:
gem install pg -v '0.12.2' -- --with-pg-config=/usr/pgsql-9.2/bin/pg_config
EDIT
Also, one last tip, after searching a bit more about this issue I found that your ruby version and architecture might affect pg's installation, I'm quoting this link:
I was hesitant to uninstall everything so I just uninstalled Ruby and reinstalled with the option set to 64-bit only (platform: "x86_64-darwin12.2.0"). After reinstalling Ruby with this option, the PG gem installed without hitch and I am back to being happy.

Related

Fix for "Nokogiri failed to build gem native extension"

The command on my Mac
$ gem install nokogiri -v '1.7.1'
gives the error
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
I tried using
bundle config build.nokogiri --use-system-libraries
but it didn't help, I get the same error
The fix was to use
xcode-select --install
and accept the GUI prompt that comes up about developer options.
Then the gem install and bundle commands worked.

Problems installing gems with RubyGems

I'm using Debian 5
Ruby version 1.8.7
Rubygems version 2.0.3
Rails version 3.2.12
I made my Ruby on Rails app and want to deploy it publicly, so I tried to install "Mongrel" without any luck and then "Unicorn" also without any luck and same error.
vps1198019:~# gem install mongrel
Building native extensions. This could take a while...
ERROR: Error installing mongrel:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/ext/http11/gem_make.out
and
vps1198019:~# gem install unicorn
Building native extensions. This could take a while...
ERROR: Error installing unicorn:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/kgio-2.8.0 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/kgio-2.8.0/ext/kgio/gem_make.out
Try using below command. Because of version mismatch, gem is not installed.
$ gem install mongrel --pre
So I found a solution for my problem by installed it more manually. I downloaded Unicorn from http://rubyforge.org/frs/?group_id=1306 (.gem file). Stored it in server. Went to that folder with terminal. Then I accessed it with
gem install --local unicorn.gem
Then it prompted that I must have kgio and raindrops so I installed them:
gem install kgio
gem install raindrops
and repeated first command.

Using RubyGems on ubuntu server

I have installed Ruby on Rails on my Ubuntu 10.04 Server by official tutorial: https://help.ubuntu.com/10.04/serverguide/C/ruby-on-rails.html
But I have some troubles with it. Please, help me!
1) I can't install ANY gem!
sudo gem install sqlite3-ruby
returns
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native
extension.
/usr/bin/ruby1.8 extconf.rb
extconf.rb:3:in `require': no such
file to load -- mkmf (LoadError) from
extconf.rb:3
Gem files will remain installed in
/var/lib/gems/1.8/gems/sqlite3-1.3.3
for inspection. Results logged to
/var/lib/gems/1.8/gems/sqlite3-1.3.3/ext/sqlite3/gem_make.out
2) When i'am trying to get Rails version by command
rails -v
Server prints:
getopt: invalid option -- 'v'
Terminating...
If you are not set on using the packages in the Ubuntu repos(and I see no reason why you'd be), I'd suggest following this guide:
http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you
Consider going through and making sure your sqlite3 libraries are installed. It looks as though you may be missing the required dependencies to build your gem. In this case you might try running this before installing your gem:
sudo apt-get install libsqlite3-dev
Also, try
rails --version
instead.

Problem install do_sqlite3 for DataMapper

sudo env ARCHFLAGS="-arch x86_64" gem install do_sqlite3
Building native extensions. This could take a while...
ERROR: Error installing do_sqlite3:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for sqlite3.h... yes
checking for sqlite3_open() in -lsqlite3... no
*** 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.
I have sqlite3-ruby installed as well as the header files, but for some reason it fails when checking for sqlite3_open()
I am having the same issue:
sudo env ARCHFLAGS="-arch x86_64" gem install do_sqlite3
Building native extensions. This could take a while...
ERROR: Error installing do_sqlite3:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/do_sqlite3-0.10.1.1 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/do_sqlite3-0.10.1.1/ext/do_sqlite3/gem_make.out
I am running Snow Leopard. I'm not sure about previous installations of sqlite3 but I did try this:
port search sqlite
And it returned the following (among others):
...
sqlite3 #3.6.17 (databases)
an embedded SQL database engine
To be honest I'm not sure what all this means. What would anyone suggest for getting do_sqlite3 installed for use in Rails 3 with DataMapper? (Also, running it without the 'env ARCHFLAGS="-arch x86_64"' gives the same errors.)
Ok, first question is why are you passing the ARCHFLAGS? That should not be necessary, if it also doesn't work without passing them, what is the output you get then?
Next question is what version of sqlite3 is it picking up? Do you have sqlite3 installed through Macports for example? Did you upgrade to Snow Leopard recently and still have an sqlite3 install from before upgrading?

Ruby-LDAP and Snow Leopard

When I install Ruby-LDAP on my Snow Leopard box, all appears to go well:
$ sudo gem install ruby-ldap
Building native extensions. This could take a while...
Successfully installed ruby-ldap-0.9.9
1 gem installed
Installing ri documentation for ruby-ldap-0.9.9...
Installing RDoc documentation for ruby-ldap-0.9.9...
But when I run the Ruby script that relies on it, I get this error:
in 'require': no such file to load -- ldap (LoadError)
I also tried setting ARCHFLAGS, since doing so appears to be required for the MySQL gem to function correctly in Snow Leopard:
$ sudo env ARCHFLAGS="-arch x86_64" gem install ruby-ldap
Unfortunately, this produces exactly the same results (or lack thereof).
How do I get Ruby to work with the LDAP libraries correctly here?
Make sure you
require 'rubygems'
first.
gem install ruby-ldap

Resources