How can I pass a parameter for gem installation wh

2019-01-16 07:23发布

问题:

I added the pg gem to my gemfile

gem 'pg'

When I run bundle install, I get this error:

Installing pg (0.10.1) with native extensions /Users/ben/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/Users/benhartney/.rvm/rubies/ruby-1.9.2-p0/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
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** 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.

It seems I need to pass in this config parameter

 --with-pg-config=/path/to/pg_config

How can I do this when I use bundle install?

回答1:

You need to set a build config option like so:

bundle config build.pg --with-pg-config=/path/to/pg_config

More info can be found in the bundle config man page



回答2:

Run 'bundle config' before 'bundle install' to set the parameters, i.e.:

bundle config build.pg --with-pg-config=/path/to/pg_config
bundle install


回答3:

with Rails3 and PostgreSQL. I do like this

>rails new test_app -d postgreSQL
>cd test_app
>mkdir .bundle
>echo "BUNDLE_BUILD__PG: --with-pg-config=/opt/local/lib/postgresql91/bin/pg_config" > .bundle/config
>bundle install

so you can keep config in source control.

for user's profile

bundle config build.pg --with-pg-config=/opt/local/lib/postgresql91/bin/pg_config

this will create ~/.bundle/config file.



回答4:

If you're using Ruby 2.x and up, then thrift 0.9.0 can't build with it. see https://issues.apache.org/jira/browse/THRIFT-2219. Thrift 0.9.2 is fixed.

Try installing: gem install rbhive -v 1.0.3.pre