Rails bundler doesn't install gems inside a group - ruby-on-rails

I have several gems including ruby-debug in a bundler group called :development. When I run the bundle command, these gems are ignored and it only installs the gems that are not in any group. How can I make sure bundler doesn't ignore the gems in the :development group?
Edit: This is what my Gemfile looks like.
source 'http://rubygems.org'
gem 'rails', '3.0.1'
# Auth gems
gem "devise", "1.1.3"
gem "omniauth"
# Bundle Mongoid gems
gem "mongoid", "2.0.0.beta.19"
gem "bson_ext"
# Asset gems
gem 'jquery-rails'
gem "jammit"
# Controller gems
gem 'inherited_resources', '1.1.2'
# View gems
gem 'haml'
gem 'formtastic', '~> 1.1.0'
# Nokogiri
gem "mechanize"
gem "json"
group :development do
gem "ruby-debug"
gem 'compass'
gem 'compass-colors'
gem 'pickler'
gem 'haml-rails'
gem 'rails3-generators'
gem "hpricot"
gem "ruby_parser"
gem 'fog'
end

Within a term session, it remembers the without option. If you first ran
bundle install --without development
it remembers that you did this and will automatically repeat this for the next
bundle install #remembers and includes --without development
running something else, like bundle install --without nothing should clear the cache. Am I right?
update 20150214: This is fixed in bundler 2.0, according to issue referenced in comment by #Stan Bondi (https://github.com/bundler/bundler/issues/2862). Thanks Stan.

If you are using rails, there will be a file config written into a hidden dir called .bundle in your rails root directory:
.bundle/config
This file, in my case, held exactly the without settings.
So I just deleted the .bundle directory:
rm .bundle -r
After that:
bundle install worked again as expected.
Using: bundler (1.5.2)

I had the same issue and --with flag worked for me. You need to pass group name, which you want to include. Like that:
bundle install --with development

gem 'aws-s3'
gem 'paperclip'
group :test do
gem 'rspec'
gem 'waitr'
gem 'faker'
end
gem 'rest-client', :group => :development
gem 'cucuber-rails', :groups => [:development,:test] (cucuber-rails gems comes under both group)
bundle install --without development #(ignore development group gems)
bundle install #(still bundle remembers --without development so result is still ignore development groups it will not install all gems)
bundle install --without nothing #(just clearing cache, now all the gems to be loaded into the ruby loadpath)
More

In fact Rails loads the :development group automatically when in development environment. Check whether Rails.env in you App really returns "development".
More Information about groups in Bundler:
http://gembundler.com/groups.html

I had a similar problem - thin in staging ignored - and the solution was to put it out if staging into the 'global' space:
gem 'thin'
group :production do
gem 'puma'
end

I've faced the same issue with bundler 2.1.4 When I checked my .bundle/config it has
---
BUNDLE_PATH: "vendor/bundle"
BUNDLE_WITHOUT: "development:test:build"
Remove groups from there and add BUNDLE_WITH to your groups.
BUNDLE_WITH: "development"
I've removed the ~/.bundle/config. but there was a file in my project directory. .bundle/config. Local directory files have precedence over the main config files.
If you can't figure out the reason, then you can just create a file in your project directory .bundle/config. and add this content there
BUNDLE_WITH: "development:test:anyGroupYouWant"

Related

Why is spring being installed on my production server?

I have a Gemfile with spring defined in :development like so:
source 'https://rubygems.org'
# Rake and rails
gem 'rake', '~> 10.4.2'
gem 'rails', '4.1.13'
group :production do
gem 'unicorn', '~> 4.8.3'
end
group :development, :staging do
gem 'spring'
end
However it's being installed on the server whenever I deploy.
The command which is issued by capistrano looks like this: cd /home/app_user/apps/ag/releases/20150921131835 && bundle install --gemfile /home/app_user/apps/ag/releases/20150921131835/Gemfile --path /home/app_user/apps/ag/shared/bundle --deployment --without development test
I do not understand why? How can I get rid of spring?
My bundler version is 1.10.6
As Yury Lebedev mentioned in a comment, you haven't excluded the staging group in the without flag, therefore gems defined as staging also installed (including spree in your case).

Rails - how do gems relate to doing 'bundle'

I'm learning Ruby on Rails from Michael Hartl's website. I have a Gemfile that looks like this:
source 'https://rubygems.org'
ruby '2.0.0'
#check and remove below if not relevant
#ruby-gemset=railstutorial_rails_4_0
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
.
.
.
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
Why is this sequence of commands correct:
`$ bundle install --without production`
`$ bundle update`
`$ bundle install`
Shouldn't it first be bundle update then bundle install --without production. Why call bundle install twice? I think the second call is redundant.
Why is this sequence of commands correct:
$ bundle install --without production $ bundle update $ bundle install
Without context, it's difficult to answer this—but one can intuit from the commands that it probably doesn't appear as one string of commands to be executed dutifully.
bundle install --without production installs exactly the versions in your lockfile, skipping any gems in a production group or with a production tag. This allows you to install only what you need to test and develop your application. (e.g., you probably don't want to waste lines with your logging service or pollute your monitoring service.) More importantly, this gives you a known-good working state for development on any machine you use.
bundle update updates the lockfile with permissible newer versions of the gems in the Gemfile. This can and will break your application if the Gemfile has not been well-crafted and versions of your dependencies have changed in the mean time. (So to answer your other question, no, you wouldn't run an update before an install.)
bundle install is most likely there to illustrate the correct command for deploying your production application: It wouldn't make any sense to skip the production gems and immediately turn around to install the production gems.
Where actually are these stuff being downloaded saved? Where are they
being installed? On my computer? I never got where they actually go or
hide. Maybe in my applications folder? But where exactly?
On your computer, in your Ruby installation. Ruby, like Perl and Python, maintains a portion of its directory structure specifically for add-on libraries.
In Ruby 2.0.0, for example, they live someplace similar to [RUBY_ROOT]/lib/ruby/gems/2.0.0/gems. For very specific purposes, it's also possible to install them locally in your Rails application's directory.
My recommendation is
1) Just do bundle, forget the rest. Not important to your learning
2) bundle install
OK, so for whatever version of ruby you are currently using this will take your Gemfile and get the right versions of those gems from rubygems.org (the site). and then install those gems on your machine for version of ruby that you are using if that version doesn't already exist on your machine. If the version exist, no download is needed, the gem version will be able to be immediately included, e.g. when offline.
If you switch ruby version then you'll usually need to bundle install again to get the right versions of those gems for the version of ruby that is currently being used on your machine.
If you use a tool such as rvm to manage your ruby versions then this is as simple as:
cd the_application_directory_for_your_rails_application
rvm use 1.9.3
bundle install
then to switch to ruby 2.0
rvm use 2.0
bundle install
You can specify specific ruby versions with
rvm use 1.9.3-p448 # e.g. for the -p448 version
You can see the 'currently available' ruby versions on your machine with
rvm list rubies
You can install a specific ruby with, e.g.
rvm install 1.9.3-p194

Heroku push rejected: can't find jquery-rails-2.0.0 in sources

I'm trying to push an Enki gem blog to Heroku and I'm getting an error
Could not find jquery-rails-2.0.0 in any of the sources
However, in the Gemfile I had
`gem 'jquery-rails'`
and I've never had a problem pushing an Enki blog with this setup before. Here's the full error message
Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
Fetching gem metadata from https://rubygems.org/.......
Could not find jquery-rails-2.0.0 in any of the sources
!
! Failed to install gems via Bundler.
!
! Heroku push rejected, failed to compile Ruby/rails app
After I got the error message I added this to the gemfile
gem 'jquery-rails-2.0.0'
I got this error message
Could not find gem 'jquery-rails-2.0.0 (>= 0) java' in the gems available on this machine.
I then tried to do
gem install jquery-rails
It gave me
Successfully installed jquery-rails-2.0.2
1 gem installed
Installing ri documentation for jquery-rails-2.0.2...
Installing RDoc documentation for jquery-rails-2.0.2...
But the push didn't work, same error
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.2.0.rc
Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
Fetching gem metadata from https://rubygems.org/.......
Could not find jquery-rails-2.0.0 in any of the sources
!
! Failed to install gems via Bundler.
!
! Heroku push rejected, failed to compile Ruby/rails app
this is the gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'heroku'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
group :production do
gem 'thin'
end
platforms :jruby do
gem 'activerecord-jdbcsqlite3-adapter'
gem 'trinidad'
gem 'jruby-openssl'
end
gem 'jquery-rails'
#gem 'jquery-rails-2.0.0'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug'
# Bundle the extra gems:
gem 'RedCloth', '~> 4.2.9', :require => 'redcloth'
gem 'ruby-openid', :require => 'openid'
gem 'rack-openid', :require => 'rack/openid'
gem 'aaronh-chronic', :require => 'chronic' # Fixes for 1.9.2
gem 'coderay'
gem 'lesstile'
gem 'formtastic'
gem 'will_paginate', '~> 3.0.2'
gem 'exception_notification', '~> 2.5.2'
gem 'open_id_authentication'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :test do
gem 'database_cleaner'
gem 'cucumber-rails', :require => false
gem 'cucumber-websteps', :require => false
gem 'factory_girl'
gem 'rspec'
gem 'nokogiri', '~> 1.5.0'
gem 'webrat'
end
group :development, :test do
gem 'rspec-rails'
end
I was getting this same error and fixed it using:
bundle update jquery-rails
In looking into it, it appears that jquery-rails 2.0.0 was yanked from rubygems: http://d.pr/i/cLms/1ReBI4U8 for whatever reason. So you (and I) likely happened to install jquery-rails when that gem was the most current version.
It's also wise to note that deleting your Gemfile.lock can be dangerous and not recommended in most cases. This causes all the latest versions of every gem without a version number in your Gemfile to be downloaded. If gems have been updated with API-breaking changes (happens more often than you might think), your app could break. But it also might not. Just be careful, run test cases if you have them. This has caused me more than one headache.
You can read a bit more about how bundler, Gemfile, and Gemfile.lock work (as well as guidance on how to properly upgrade certain gems) here: http://viget.com/extend/bundler-best-practices
Worked for me:
delete the Gemfile.lock
removed the rails version from the line => gem 'rails' (jquery was already without a v number)
run the command "bundle install"
run also "bundle update jquery-rails" to make sure everything is updated
IMPORTANT, commit the new .lock file => run the "git add ." and "git commit ..."
push everything
Update:
I am going through mhartl's Rails Tutorials and had to update jquery-rails, '2.0.1' in the Gemfile, to get the bundle update jquery-rails going.
Thanks,
Jatin
i had similar issue by changing in Gemfile jquery-rails-2.0.0 to 2.0.1 will solved my problem.
Michael,
I had to remove the version number from my jquery gem from 2.0.0 and let it pull the latest for this to work. I am on rails 3.2.8.rc2 and running on the cedar stack of heroku. Best of luck!
Mark

Why Bundler.require is not working the way it should

I have an application where I segregated all my gem based on groups
source 'http://rubygems.org'
...
...
...
group :development, :test do
gem 'ruby-debug19', :require => 'ruby-debug'
gem 'web-app-theme', '>= 0.6.2'
gem 'faker'
gem 'mailcatcher'
gem "pry"
gem 'annotate'
gem "unicorn"
gem "capistrano"
end
The important Thing over here is ruby-debug19
now in my config/application.rb
I have defined
Bundler.require *Rails.groups(:assets => %w(development test))
Still when I start my server
rails server --debugger
it give me this below error
`require': no such file to load -- ruby-debug (LoadError)
I have remove the ruby-debug19 from development group and put it in default it the server works
I compared the both the Gemfile.lock in either case
cat Gemfile.lock > intial_lock (When ruby-debug19 is in development group)
ran
bundle list
cat Gemfile.lock > final_lock (When ruby-debug19 is in default group)
also did a
diff initial_lock final_lock
No difference indicating the file are same
I also tried with
Bundler.require(:default, :assets, Rails.env)
Still no success
Can anyone let me know why Bundler.require is not working the way it should have
Check if you have not fall into the .bundle directory trap in your application directory It happen when you any time run anytime bundle install with --without options
Straight from bundle Gemfile manual
After running bundle install --without test, bundler will remember
that you excluded the test group in the last installation. The next
time you run bundle install, without any --without option, bundler
will recall it.
just remove .bundle/config directory from your application directory please first check the content first before removing it
Hope this help

bundler incorrectly trying to install "development" and "test" group gems in production

I have a small web app, which uses a bunch of gems. Some of them are only used for test and development environments. Now, when I try to start unicorn on the production server using the following command, it fails.
unicorn_rails -E production -D -c config/unicorn.rb
The error I see in the log files is:
Refreshing Gem list
Could not find gem 'spork (>= 0.9.0.rc2, runtime)' in any of the gem sources listed in your Gemfile.
Try running `bundle install`.
I've pasted my gemfile below:
source 'http://rubygems.org'
gem 'rails', '3.0.1'
gem 'unicorn'
gem 'mongoid', '>= 2.0.0.beta.19'
gem 'devise'
gem 'cancan'
gem 'haml', '>= 3.0.0'
gem 'bson'
gem 'bson_ext'
gem 'formtastic'
gem 'bluecloth'
group :production do
gem 'capistrano'
end
group :development do
gem 'haml-rails'
gem 'hpricot', '0.8.2'
gem 'ruby_parser', '2.0.5'
gem 'less'
gem 'rspec-rails', '>= 2.0.1'
end
group :development,:test do
gem 'spork', '>=0.9.0.rc2'
gem 'mongoid-rspec'
end
group :test do
gem 'factory_girl_rails'
gem 'autotest'
gem 'cucumber-rails'
gem 'cucumber'
gem 'capybara'
gem 'shoulda'
gem 'database_cleaner'
gem 'test_notifier'
gem 'rspec', '2.0.1'
gem 'launchy'
end
Bundler is supposed to detect the right environment and ignore the other gems, right? Right now, I am deleting all the lines which are not in the default group on the server to get this working, but that's an ugly hack.
After a lot of digging I found the fix for this issue. All I had to do was run bundle install --without development test before starting the server. This adds a .bundle/config file in the rails root with the line BUNDLE_WITHOUT: test:development . Now whenever you run bundle install or start the server it'll ignore those groups.
From the documentation
The Bundler CLI allows you to specify
a list of groups whose gems bundle
install should not install with the
--without option. To specify multiple groups to ignore, specify a list of
groups separated by spaces.
bundle install --without test bundle
install --without development test
After running bundle install --without
test, bundler will remember that you
excluded the test group in the last
installation. The next time you run
bundle install, without any --without
option, bundler will recall it.
Also, calling Bundler.setup with no
parameters, or calling require
"bundler/setup" will setup all groups
except for the ones you excluded via
--without (since they are obviously not available).
In my case it was installing gems from jenkins env. So i had to set my own bundle_without variable in capistrano.
Gemfile
group :test, :development, :jenkins do
gem 'test-unit', '1.2.3'
gem 'rspec-rails'
end
deploy.rb
set :bundle_without, [:development, :test, :jenkins]
You haven't defined a production group =)

Resources