当我运行bundle install时,如何为gem安装传递参数?

ben*_*ben 63 gem ruby-on-rails bundler ruby-on-rails-3

我将pg gem添加到我的gemfile中

gem 'pg'
Run Code Online (Sandbox Code Playgroud)

当我跑bundle install,我得到这个错误:

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.
Run Code Online (Sandbox Code Playgroud)

看来我需要传入这个配置参数

 --with-pg-config=/path/to/pg_config
Run Code Online (Sandbox Code Playgroud)

我用的时候怎么bundle install办?

idl*_*ers 84

您需要设置一个构建配置选项,如下所示:

bundle config build.pg --with-pg-config=/path/to/pg_config
Run Code Online (Sandbox Code Playgroud)

可以在bundle config手册页中找到更多信息


Mar*_*ark 15

在'bundle install'之前运行'bundle config'来设置参数,即:

bundle config build.pg --with-pg-config=/path/to/pg_config
bundle install
Run Code Online (Sandbox Code Playgroud)


Jir*_*ong 9

使用Rails3PostgreSQL.我喜欢这个

>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
Run Code Online (Sandbox Code Playgroud)

所以你可以在源代码管理中保持配置.

用户的个人资料

bundle config build.pg --with-pg-config=/opt/local/lib/postgresql91/bin/pg_config
Run Code Online (Sandbox Code Playgroud)

这将创建〜/ .bundle/config文件.