I am trying to update a gem version to a particular version. But whenever I run command bundle update gem, it is updating the latest version of that gem.
Even on running command bundle update gem -v "x.x.x" it is still updating to the latest one.
Is there any way to update a gem version to a particular version?
In your Gemfile specify the gem version. For example:
gem "foo", "= 1.0.0"
then run bundle update foo
Related
I want to get a Gem's version without running bundle install.
Which is to say I want figure out what version bundle is planning to install without actually installing the gem.
Say read it from the Gemfile.lock(and Gemfile) combined.
Is there a way I can resolve what version bundler plans to install?
I need this because I want to cache the expensive installs while running docker build.
Gems like rails(nokogiri) take a while to install and I would like to do gem install rails -v ... in a previous step before running bundle install.
For this purpose i need to get the rails version before hand
If you add a new gem to your gemfile, but don't do bundle install, it doesn't install yet. Instead, you can run bundle lock, which generates a new lock file. This includes the gem version of the new gem that would be installed.
By running bundle show new_gem, it shows it isn't actually installed.
To be sure maybe get a backup of the original Gemfile.lock before running the command though.
By default if no version is specified in the Gemfile, running bundle install will attempt to install the latest version of the gem which is compatible with the rest of the gems and ruby version in your project. This will create a Gemfile.lock file if one doesn't already exist. If a Gemfile.lock file is already committed to git repo, it should then install the versions specified in Gemfile.lock. The point of bundler is to handle dependencies to insure your stack works correctly.
To see the version of a gem bundler is currently using you can run
bundle show rails
You will probably want to specify the ruby version in the Gemfile for example
ruby '~> 2.5' #
You can specify exact version of a gem in the Gemfile like this which you should be able to rely on to be the version bundler will install so long as it's compatible with the rest of the stack. bundle install will throw errors if there are incompatible gem versions.
gem 'rails', '4.2.11' # this will always install only this version.
You may also use pessimistic operator (~>) to set for only minor updates
gem 'influxdb', '~> 0.6.1' # could go to 0.6.2 but never 0.7.0
You can also set minimum versions like this although it's probably not what you need for your question.
gem 'pg_query', '>= 0.9.0'
If you have a Gemfile.lock already in your repo you can see which version would be installed by running for example:
gem show rails
Which would show you the version and weather it or not it is currently installed.
For more info see bundle --help
The current official version of Rails is 4.0.3.
When I create a new Rails app I get version 4.0.2, and then I have to update the Gemfile and run bundle update.
What should I do to have the latest version of Rails (and all other default gems) on my system, such that when creating a new app it automatically has the latest version?
If you run gem update it will update all installed rubygems. This includes rails and all gems on your system.
You should be careful though since you may not want to update everything. In that case you can specify gems individually.
gem update rails
To get the latest gems you can run
gem update
To simply see what gems can be updated you can run
gem outdated
To update just the rails gem you can do
gem update rails
In my Gemfile I have:
gem 'rails'
until yesterday it works well, my rails version was 3.2.9.
I've added no new gems and today, after running bundle update I see that it installs rails-0.9.5.
Why?
Running bundle update without specifying a gem to update is a bad idea if you haven't set the minor version in your Gemfile. The reason for this is because you will likely upgrade a gem that has a different public interface and it will break your application.
I'd recommend specifying the major and minor version of Rails in your Gemfile so that it "locks" it down so it will only upgrade the patch level:
gem "rails", "~> 3.2.9"
Then when you want to upgrade it, just run:
bundle update rails
This will update Rails to the latest patch (3.2.x) and as long as they are following semantic versioning, you won't have to worry about it breaking your app.
I'm using the thumbs_up gem and on github there's a master branch (0.4.6) and an engine branch (0.3.2). When I require the gem in my Gemfile with
gem 'thumbs_up'
I see that version 0.4.6 was installed. I verify this is the right version running in my dev environment by doing bundle exec gem which thumbs_up and when I look at the VERSION file I see it's 0.4.6.
So when I look at the code I'm expecting to find an unvote_for method but it doesn't have one. Instead it has one called clear_votes. Now I'm confused because clear_votes is supposed to be in version 0.3.2 but as far as I can tell, I'm on version 0.4.6.
Any ideas what's going on here?
By default, the gem used is the latest available when running 'bundle install'. You can specify a version (or version constraints) in the Gemfile. To update the version of the gem used, you have to run bundle update <gemname>, and it will do so according to your gemfile.
About your problem : ensure that your server/console command is prefixed with bundle exec. You check also which versions of thumbs_up are installer on your system, and remove the version you don't need anymore.
You use Bundler so you can know which version of you gem is using in your Gemfile.lock. Bundler have and use only one version by gem.
I want to make a Rails Bundle Package for a client. I am using Rails 3.0.3 and Ruby 1.9.2. What is the process if I need to update the bundle package with new gem versions?
If you want to update to a specific version, use #Ferdy's answer, but if you just want to update to the most recent version run:
bundle update gem_name
This will update your gem to the latest version, and also update all of its dependencies. It will also update your Gemfile.lock file so that you can commit it to source code. Other systems will now just need to run:
bundle install
to get the update.
You want to update the gems used in a rails project? My guess is that you update the versions in the GemFile
gem 'name', 'version'
and then run bundle install.. This will install all the appropriate versions.