An error occurred while installing pg (0.12.2), and Bundler cannot continue
bundler, railstutorial.org, ruby-on-rails-3, rubygems
Solution
I'm following the same tutorial and I think it's redundant to run `update` without modifying existing dependency, but in this case it's even causing problems because `update` command has not `--without` argument.
I stumbled upon Rails 3 cheatsheet which mentions bundler workflow this way:
After adding or removing dependencies from Gemfile
- `$ bundle`
- Commit Gemfile and Gemfile.lock
After modifying existing dependency versions
- `$ bundle update`
- Commit Gemfile and Gemfile.lock
I read man pages for `bundle update` and tried RECOMMENDED WORKFLOW which consists of running `bundle update` after `bundle install`.
In my case (some output omitted):
$ 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
I tried it with new RVM gem set and everything was installed correctly.
After that `Gemfile.lock` contains `pg (0.12.2)` and deploying to Heroku works.
RECOMMENDED WORKFLOW
In general, when working with an application managed with bundler, you should use the following workflow:
After you create your Gemfile for the first time, run
`$ bundle install`
Check the resulting Gemfile.lock into version control
`$ git add Gemfile.lock`
When checking out this repository on another development machine, run
`$ bundle install`
When checking out this repository on a deployment machine, run
`$ bundle install --deployment`
After changing the Gemfile to reflect a new or update dependency, run
`$ bundle install`
Make sure to check the updated Gemfile.lock into version control
`$ git add Gemfile.lock`
If bundle install reports a conflict, manually update the specific gems that you changed in the Gemfile
`$ bundle update rails thin`
If you want to update all the gems to the latest possible versions that still match the gems listed in the Gemfile, run
`$ bundle update`
Problem
I'm following the Michael Hartl Ruby on Rails Tutorial & there is a part where he is he he instructs you to update your Gemfile to include: ``` group :production do gem 'pg', '0.12.2' end ``` And then enter the below commands in your terminal: ``` bundle update bundle install --without production ``` When you run the bundle update command it throws back the below errors. ``` 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:$ ``` I was able to overcome this error easily be removing the `'pg', '0.12.2'` gem from the Gemfile & replacing it after running the `bundle update` command. This seems to work fine as the `'pg', '0.12.2'` gem is aslo omitted in the `without production` flag in the latter `bundle install --without production`. The `'pg', '0.12.2'` gem is only needed for deploying to heroku with the correct database & everything works fine even when I deployed it to heroku but I'm just wondering if this is an error in the Tutorial or am I missing something bigger here? It's also annoying to have to remove this Gem everytime I run `bundle update`, is `bundle update` really that necessary? Thanks in Advance