I did a clean install of rails 3.0.6. My app is running fine, except that I cannot use all the gems that didn't come with rails 3. All of them are in gem list. I also have them in Gemfile and have ran bundle install and bundle update.
For example, with matthuhiggins-foreigner:
upon rake db:migrate, it complains
that add_foreign_key is not defined.
I have the same problem with less:
no .css generated from .less)
geokit-rails3:
Unknown key(s): origin, within
gem which geokit-rails3 returns:
/Library/Ruby/Gems/1.8/gems/geokit-rails3-0.1.3/lib/geokit-rails3.rb
gem environment returns:
RubyGems Environment:
- RUBYGEMS VERSION: 1.5.0
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-10
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/administrator/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
I have looked into this problem for a long time. Please help!
Thanks!
Rails 3 does not load any gems that are not listed in your Gemfile, even if they are installed on your system. You need to explicitly list them there first.
The typical workflow in R3 is not to install your gems and then use them, but to write entries in the Gemfile and then install them by installing bundler with "gem install bundle" and getting all the remaining gems with "bundle install". Bundle install will install any required gems you do not already have, but will use the ones you do have.
(Bundle update, suggested by another user, will bump all your gems to the most recent available version that matches your requirements as laid out in the Gemfile, even if the ones already installed satisfy the requirements). i.e. if you need foo_gem >= 1.0 and you have foo_gem 1.0.1 installed, "bundle install" won't change it but "bundle update" will install foo_gem 1.0.3 if it's available.
If you are working on multiple applications that have conflicting (or potentially conflicting) gems, then I recommend learning about RVM and creating a gemset for each project. This is especially valuable if you are still working on any Rails 2.x projects alongside your R3 projects.
Try this:
Update gem by running gem update --system
Make sure your gemfile lists the gems
Run bundle update to update all your gems in the gemfile
Hopefully that should do the trick.
I came back to this problem after a few days and I fixed all the issues!
matthuggins-foreigner gem is called foreigner, so I added this to Gemfile:
gem 'foreigner'
With geokit, I simply followed the instructions here:
https://github.com/jlecour/geokit-rails3
With less, I installed the less gem and the more plugin, then restarted the server:
https://github.com/cloudhead/more
Related
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
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
Installation of postgres fails with this error : "Can't find the 'libpq-fe.h header"
Looks like a lot of people faced this problem, good news is : stackoverflow has the answer ;)
Can't find the 'libpq-fe.h header when trying to install pg gem
(or at least it should help you to look in the right direction)
I'm running rvm with ruby 1.9.3. I've ran bundle install and it worked fine. But when I run bundle install --deployment I get this:
volunteer-app ➜ bundle install --deployment
Fetching gem metadata from http://rubygems.org/.......
Installing rake (0.9.2.2)
Gem::LoadError: Could not find rubygems-bundler (>= 0) amongst []
An error occured while installing rake (0.9.2.2), and Bundler cannot continue.
Make sure that `gem install rake -v '0.9.2.2'` succeeds before bundling.
After this is ran I look in the vendor/bundle/ruby directory and it shows 1.9.1. So it looks like bundle install --deployment isn't recognizing my gems in from rvm's default ruby version 1.9.3.
Any thoughts on what I could be missing.
Edit
Here's my gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.24
- RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/sosl/.rvm/gems/ruby-1.9.3-p194#teer
- RUBY EXECUTABLE: /home/sosl/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
- EXECUTABLE DIRECTORY: /home/sosl/.rvm/gems/ruby-1.9.3-p194#teer/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/sosl/.rvm/gems/ruby-1.9.3-p194#teer
- /home/sosl/.rvm/gems/ruby-1.9.3-p194#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
It's a bug in both rubygems-bundler and bundler, I have already fixed it for rubygems-bundler and a fix for bundler is waiting for merge.
Fastest way to fix is to update rubygems-bundler:
gem update rubygems-bundler
For reference here is pull request for bundler:
https://github.com/carlhuda/bundler/pull/1925
I really feel for you as I just went though something simular last night. While I am certainly not an expert (I am just a student of RoR as you are) can I make some suggestions?
After you use RVM to change into your RUBY version, run a "local" gem list to see what gems are installed locally. Do you have the gem installed in your local gems?
Sometimes gem files get "Jumbled" and stop working altogether. Have you tried to uninstall and then reinstall the gems? The command is simple. In your console type "gem uninstall (the name and version number of the gem you wish to uninstall). It may reply that the gem you wish to uninstall has dependencies on other gems you have installed. Don't worry once you reinstall those gems the dependencies will be satisfied.
I don't know if Bundler is installed automatically or not. Is it listed in your "Local" gems or in your gemfile.lock?
Best of luck in correcting this.
The project I'm about to work on asks for version 1.0.10 of bundler and version 0.8.7 of rake. My global gemset has slightly newer versions of these gems. I.e., the install instructions for the new project look like this:
rvm gemset use rails3
gem uninstall -x bundler
gem install bundler -v 1.0.10
gem uninstall -x rake
gem install rake -v 0.8.7 # Rake needs to be at 0.8.7
What happens is that when I'm in this new rails3 gemset I can't uninstall the existing gems (and personally I don't want to) because they exist in the global gemset.
So, question: can I somehow hide those two gems that exist in the global gemset?
I can list the gems:
$ gem list
*** LOCAL GEMS ***
addressable (2.2.6)
archive-tar-minitar (0.5.2)
awesome_print (1.0.1)
bundler (1.0.21, 1.0.10)
...
rake (0.9.2.2, 0.8.7)
...
Maybe an ancillary question would be: since I have installed the older versions into the the rails3 gemset, will rvm prefer those because the fact they were specifically installed somehow overrides the version in global, or will rvm take the gems with the highest version number?
any command except bundle should be prefixed with bundle exec and this will assure proper version of gem is used (using Gemfile)
you can avoid writing always bundle exec by using my gem rubygems-bundler
for running bundle command - rubygems will select latest available version if you do not specify one ex. bundle _1.0.10_ exec rake db:create
I've added a gem 'koala' to my Gemfile and seems to have thrown gem versions out of whack when I run the 'bundle install' command:
Bundler could not find compatible versions for gem "faraday":
In snapshot (Gemfile.lock):
faraday (0.6.1)
In Gemfile:
koala (~> 1.2.0beta1) depends on
faraday (~> 0.7.4)
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
How can I resolve this conflict?
Delete the contents of Gemfile.lock, and run bundle install again. That's been working for me.
Did you run bundle update as the error message points out? bundle install handles changes to the Gemfile and bundle update upgrades gems that are already managed by Bundler. The Gemfile.lock file locks in version numbers, bundle update will update any of those that aren't directly specified in your Gemfile (like gem 'rails', '3.0.9').
Deleting the Gemfile.lock will work, but running bundle update is better.
You can't simply delete you Gemfile.lock if that is a solution then why Gemfile.lock is exist in the first place, you code depend on the versions locked in this file, try to only update the Gem which cause the conflict by using bundle update gem_name and you have to check the ReadMe if any changes needed to work with the new version otherwise you are breaking your code or others code.
I found that by removing the specified version of rails solved the problem for me ....
instead of:
gem rails, '4.0.4'
I did
gem rails
followed by deleting the Gemfile.lock and re-running bundle install
If deleting Gemfile.lock doesn't work there is another possibility:
It may be possible a gem you are depending on has inadvertently included its own Gemfile.lock in its .gem file. The solution is to update the offending gems to not include a Gemfile.lock, rebuild and reinstall.
An alternative is to go to your Gemfile.lock and delete all references to the offending gem (in this case the faraday gem).
Then run bundle install and it'll update the Gemfile.lock to have compatible versions of the gem where it needs.
If you want to be extra safe you can go to the Gemfile and specify the versions of the gems you want before doing this.
This was the only way I was able to get bundle install running for one of the systems that I'm maintaining.
This system has a lot of old gems in its dependencies (58 gems at the time of writing) and so bundler has a hard time coping with it.
If I delete the Gemfile.lock and run bundle install it'll blow up with multiple Bundler could not find compatible versions for gem xxxxxx errors.
If I run bundle update it would also blow up with multiple Bundler could not find compatible versions for gem xxxxxx errors.
Note: Removing Gemfile.lock will have new entried to different gems. This might not be acceptable in your project. Your team or lead will not allow this.
If you are working on legacy codebase, for example Rails 3.2 or similar
In case you hit this kind of errors,
see the last line of Gemfile.lock which seems like
whenever (~> 0.9.4)
wicked_pdf (= 1.1.0)
will_paginate (= 3.1.8)
wkhtmltopdf-binary-edge (~> 0.12.4.0)
BUNDLED WITH
1.16.6
now install the version of bundler mentioned in the file. In my case its1.16.6.
gem install bundler -v 1.16.6
now remove the older version. How?
$ gem uninstall bundler
Select gem to uninstall:
1. bundler-1.16.6
2. bundler-2.1.4
3. All versions
> 2
Successfully uninstalled bundler-2.1.4
$ bundle -v
Bundler version 1.16.6
Now it will install successfully
This problem was fixed in 0.9.8, but seems to have recurred in the 1.x branch.
In my Gemfile I have a group for the test and development environments that use the rspec gems.
On my production server rspec is not installed.
I used the command bundle install --without test development in my
rails app
Starting my rails app in production mode gives the exception:
Could not find gem 'rspec (>= 0)' in any of the gem sources listed in
your Gemfile.
If I comment out the test group the same error happens with the development group.
The same problem exists if I start in development mode, then it tries to load the gems in the test group.
It seems that bundler completely ignores the environment groups and tries to load all gems in Gemfile:
group :test do
gem "rspec"
end
group :development do
gem "rspec-rails"
end
versions:
bundle 1.0.15
rails 3.0.7
ruby 1.9.2-p180
I was having this problem too, the problem was that .bundle/config file had something like
"--without development test"
even tho I had never ran the bundle command with this parameters(maybe I cloned the repository from the Webbynode server and their system added this automatically for production...)
anyway, the fix was
rm .bundle/config
bundle install