Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top