I've been working with Rails 3 for some time now and never came across an answer for the difference between running bundle and bundle install to install gems in your Gemfile.
Is there any difference between the two commands?
No. install is just the default option for the bundle command. Don't run either in your Gemfile, however, just specify the gem "fubar" there -- bundler knows how to read and process that file.
Related
I have this in my Gemfile.lock
sequel (5.15.0)
I want to downgrade the gem version to the 4.39.0 so I go in my Gemfile and add a version next to the gem declaration:
gem 'sequel', '4.39.0'
and run bundle exec bundle install
But it gives me:
You have requested:
sequel = 4.39.0
The bundle currently has sequel locked at 5.15.0.
Try running `bundle update sequel`
If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`
Run `bundle install` to install missing gems
.
So I try to run bundle exec bundle update sequel but it returns me the same message.
How can I downgrade the gem?
You need to just call
bundle update sequel
without the bundle exec in front.
The issue you experienced is caused by bundle exec evaluating your current Gemfile for executing the latter command first. Here, it finds the difference between the specified gems in the Gemfile and your current Gemfile.lock and bails out.
In general, no bundle calls need to ever be prefixed with a bundle exec.
First try to update the dependent gems. It could be that there are some broken dependencies to other gems if you are downgrading.
Best practice:
bundle update sequel dependent_gemnames...
If you do not find out the dependent gems you can also try to update all your gems. But attention! This can cause unwanted side effects.
bundle update
And the last and ugliest option is to remove your Gemfile.lock and run
bundle install
This will rebuild your full Gem Stack and should be able to create a working Gemfile.lock
When I run $ rails -server to start a server, there comes an error:
Could not find gem 'sqlite3' in any of the gem sources listed in your Gemfile or available on this machine.
Does that mean I did not install sqlite3? How can I resolve the issue?
First, you have to install all Gems from your Gemfile.
This can be done with bundle install or in short bundle.
If this command executed successfully, you can run your server with rails s.
But I think it's better for you, to start with a tutorial.
server and s are not a switch, but a sub-command.
Run
$ rails server
or
$ rails s
I run into this issue previously, that is because you run bundle install, miss some gems, so you can $ bundle install again,
and you can test the sqlite if is installed:
$ sqlite3 --version
If successed, you can test the rails server.
I'm learning Rails with tutorials from Ruby on Rails by Michael Hartl: https://www.railstutorial.org/book
I used the following command to generate a controller:
rails generate controller StaticPages home help
Which generates the following error regarding version conflicts:
check_version_conflict': can't activate bundler-1.12.4, already
activated bundler-1.13.0.pre.1 (Gem::LoadError)
I don't know which bundler version to use. The current version of bundler is: 1.13.pre.1
The following command continued failing due to about five gem dependencies that failed to install automatically, which included listen and nokigiri.
bundle install --without production
I tried installing the dependent gems manually, but I'm still having issues.
How do I resolve the check_version_conflict issue with Bundler when generating Rails controllers?
I'll accept an answer that instructs removing current Ruby libs and installing a new development environment from scratch.
Bundler will install project-specific versions of your gems so that you don't have to manage global dependencies.
In effect, if you install Rails with bundler and you also install it with sudo gem install rails or something like that, you'll have two versions on your computer. By default, calling rails will refer to the global version.
If you call bundle exec rails (or bundle exec <gem_name>), it will call the bundler-specific version.
Ten steps to resolve your issues with Bundler
(optional) Uninstall Ruby. There are many ways to do so, here's one: https://superuser.com/questions/194051/how-to-completely-remove-ruby-ruby-gems-on-mac-os-x-10-6-4
(optional) Use rbenv to install Ruby. Follow instructions here: https://github.com/rbenv/rbenv
Make a repo directory that will house your future Rails app
From the command line:
mkdir repo
cd repo
Install Bundler and create a Gemfile for the directory
From the command line:
gem install bundler
bundle init
Open the repo/Gemfile with your editor, and configure it to instruct Bundler which version of Rails to install
In repo/Gemfile:
source "https://rubygems.org"
gem "rails", "4.2.6"
Install Rails via Bundler
From the command line:
bundle install
Create a new Rails app using Bundler, and cd into it
From the command line:
bundle exec rails new whatevs
cd whatevs
Your Rails app will have a Gemfile by default. Open it and add the gems you wish to use in your app.
In repo/whatevs/Gemfile:
gem 'nokogiri', '1.6.8'
From repo/whatevs/ directory, install your app's Gems via Bundler
From the command line:
bundle install
From repo/whatevs/ directory, generate a controller
From the command line:
bundle exec rails generate controller static_pages home help
I'm trying to understand what exactly happen when I'm installing gems.
At first I thought that using the "gem install gem_name" command (and after it the "bundle install) will make sure I have the proper files and dependencies and then it will update the gemfile.
But I've noticed that whenever I add gem using the commend line it doesn't appears at the gemfile yet I'm still able to use its functionality.
so is there is any reason to use the comment "gem install gem_name" insted of just adding the gem name to the gemfile?
The reason to use a Gemfile is that you can install all required gems in a single go.
Imagine that you work in a development team and a new member starts contributing to your application.
Al he has to do is checkout the repository and run bundle install.
Only use the command gem install if you just want to install a gem that is not nessecarily relevant to your project.
If the project requires the gem; put it in the Gemfile.
I'm going through Micharl Hartl's well known Rails tutorial, and this piece is confusing me. Every time a new app is set up, these commands are run:
$ bundle install --without production
$ bundle update
$ bundle install
I don't really get why install is being run twice. What is the effect of these three commands run in this sequence?
You should not have to run bundle install twice as bundle update will also install all of your gems (as well as updating them to their most current version). I have not read the tutorial you mentioned but perhaps the purpose of the second install is to install all of the gems, including those reserved for production.
Your second question, what is the effect of these three commands:
bundle install --without production
Inspect the gemfile, ignoring gems that are reserved for production
Resolve all dependencies
Install all gems and dependent gems
Save the exact version of each gem to Gemfile.lock
bundle update
Inspect the gemfile
Resolve all dependencies from scratch using the newest version of each gem and completely ignoring Gemfile.lock
Install all gems and dependent gems
Save the exact version of each gem to Gemfile.lock
bundle install
Because this is the first run of the production gems, inspect the gemfile and resolve dependencies of the production gems
Use Gemfile.lock for exact versions of all other gems to be installed
Install all gems and dependent gems
Save the exact version of each gem to Gemfile.lock
Hoped this helped, for more detailed info about the two commands check out this and this.
$ bundle install --without production prevents bundler from installing any of the production gems. It also gets saved in your local repository and you don't have to run it more than once. Any subsequent run of bundle install will include --without production.
bundle install installs only the missing gems from your Gemfile, while bundle update updates/installs every single gem to the latest version as specified in the GemFile..