我正在关注Michael Hartl Ruby on Rails Tutorial&有一个部分,他指示你更新你的Gemfile包括:
group :production do
gem 'pg', '0.12.2'
end
然后在终端中输入以下命令:
bundle update
bundle install --without production
运行bundle update命令时,会抛出以下错误。
sample_app:$ bundle update
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.0.3)
Using i18n (0.6.4)
etc
[omitted lines for brevity]
etc
Using railties (3.2.12)
Using coffee-rails (3.2.2)
Installing diff-lcs (1.1.3)
Using jquery-rails (2.0.2)
Installing pg (0.12.2)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/ross/.rvm/rubies/ruby-1.9.3-p392/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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
etc
[omitted lines for brevity]
etc
Gem files will remain installed in /home/ross/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2 for inspection.
Results logged to /home/ross/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.12.2/ext/gem_make.out
An error occurred while installing pg (0.12.2), and Bundler cannot
continue.
Make sure that `gem install pg -v '0.12.2'` succeeds before bundling.
sample_app:$
我能够轻松地从 Gemfile &中删除'pg', '0.12.2'
gem。在运行bundle update
命令后替换它。这似乎工作正常,因为后者'pg', '0.12.2'
的{{1}}标志中省略了without production
gem。
仅在使用正确的数据库和/或部署到heroku时才需要bundle install --without production
gem。一切都运行正常,即使我将它部署到heroku但我只是想知道这是教程中的错误还是我错过了更大的东西?
每次运行'pg', '0.12.2'
时都必须删除此宝石也很烦人,bundle update
真的有必要吗?
先谢谢
答案 0 :(得分:4)
我正在遵循相同的教程,我认为在不修改现有依赖关系的情况下运行update
是多余的,但在这种情况下,它甚至会导致问题,因为update
命令不是--without
参数。
我偶然发现Rails 3 cheatsheet以这种方式提到了捆绑工作流:
在Gemfile
中添加或删除依赖项后
$ bundle
- 提交Gemfile和Gemfile.lock
醇>修改现有依赖项版本
之后
$ bundle update
- 提交Gemfile和Gemfile.lock
醇>
我为bundle update
阅读了man pages并尝试了 RECOMMENDED WORKFLOW ,其中包括bundle update
后bundle install
的运行。
在我的情况下(省略了一些输出):
$ bundle install --without production
Resolving dependencies...
Using rake (10.0.3)
...
Installing rspec-core (2.11.1)
Your bundle is complete!
Gems in the group production were not installed. <-- check
$ bundle update
Resolving dependencies...
Using rake (10.0.3)
...
Using uglifier (1.2.3)
Your bundle is updated!
Gems in the group production were not installed. <-- check
我尝试使用新的RVM gem set并且所有内容都安装正确。
之后Gemfile.lock
包含pg (0.12.2)
并部署到Heroku工作。
推荐的工作流程
通常,在使用使用bundler管理的应用程序时,您 应使用以下工作流程:
首次创建Gemfile后,运行
$ bundle install
将生成的Gemfile.lock检入版本控制
$ git add Gemfile.lock
在其他开发计算机上签出此存储库时,请运行
$ bundle install
在部署计算机上签出此存储库时,请运行
$ bundle install --deployment
更改Gemfile以反映新的或更新依赖项后, 运行
$ bundle install
确保将更新的Gemfile.lock检查到版本控制
$ git add Gemfile.lock
如果bundle install报告冲突,请手动更新特定的 您在Gemfile中更改的宝石
$ bundle update rails thin
如果您想将所有宝石更新为最新版本 仍然匹配Gemfile中列出的宝石,运行
$ bundle update
答案 1 :(得分:1)
postgres的安装失败并出现此错误:“找不到'libpq-fe.h标头'
看起来很多人都遇到了这个问题,好消息是:stackoverflow有答案;)
Can't find the 'libpq-fe.h header when trying to install pg gem
(或者至少它应该帮助你朝正确的方向看)