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.
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
I'm using RVM to manage the different ruby versions I have. One particular application is using an older ruby version (2.3.1), and I've noticed that, once I've changed to that version and run rails server on it, it doesn't work because I'm required to change a whole cascade of Gems or other files, such as nokogiri, to make it run.
Generally, from what I've read online, I should just do a simple bundle install to do all of this before running rails server. However, it doesn't work as there are more conflicting things in this file, specifically that the versions are hard coded into it.
Based on this, how can I run this app on my local server, if the above steps I've done, just doesn't work? I'm using Ubuntu, if that helps.
You're dealing with what is known as dependency issues. The point of Gemfile and Gemfile.lock is to insure that there will be no dependency issues for the application and bundle install will handle that. However it is common for versions to be set in the Gemfile to lock to a specific major release version which might allow for minor version updates. This will look something like:
#Gemfile
gem 'rails', '4.2.10'
gem 'pg', '0.20.0'
gem 'after_party', '~> 1.10' #minor version updates will run here
gem 'kaminari', '~> 1.1'
ruby '2.3.6'
This ia a brief example. Now when you run bundle install it will make sure everything is compatible with these versions. While running bundle update will only update the versions with ~> before the version and will upgrade only minor semantic versions as they are not supposed to have breaking changes.
So, why is your app not working? Well the Gemfile should have contained a ruby version. RVM should determine your ruby version in .ruby-version file in base of your rails app and should match the version in Gemfile. If you need to upgrade your ruby version bundler will help insure all your gems are compatible with that version and with each-other. You'll first need to upgrade your ruby version with RVM, then set it in Gemfile.
However, there is no guarantee that out of date gems will be compatible. That's the whole point of locking them so that you know which versions are stable at a give point in time. Updates / upgrades to gems have to be tested for compatibility which can sometimes be a project.
Also see Rails Bundle, gems conflicts, best way to solve it
You can create a .rvmrc file or .ruby-version and .ruby-gemset files for isolating gems for your projects. Here's the official documentation on that - https://rvm.io/workflow/projects#project-file-ruby-version
you can add
echo '2.3.1' > .ruby-version and echo 'newgemset' > .ruby-gemset into working folder
then run
cd ./
rvm install ruby-2.3.1
gem install bundle
bundle install
I am a newbie so please bear with me :)
I am currently working on my personal project running on rails 5.0.0.rc2. How can I best upgrade my project to use the latest version 5.0.0?
I did some research and found that I could just easily change the rails gem in Gemfile and run 'bundle update rails'. I don't know if this is the best way, but if it's not, what's the best way?
Thanks!
Go to your Gemfile, check gem 'rails' and set it's version like this
gem 'rails', '5.0.0'
the use bundle to install it by running
bundle install
or
bundle
you may encounter some dependencies that require you to run
bundle update
Changing the rails version in the Gemfile would be enough. Also be sure to check out railsdiff.org for changes in the project directory (config files, etc.)
I'm on Rails 4.0.4.
I would like to try out the latest relase candidate for 4.1.
How would I upgrade my Rails application to the latest RC?
If a gem's version number has a letter in the version then it is considered to be 'pre-release' and will be skipped by bundler unless you specify otherwise in your Gemfile.
If you want to use a pre-release version of a gem:
# Gemfile
gem "rspec-rails", ">= 6.0.0-rc1", "< 6.1"
This will install 6.0.0-rc1 and then update to anything in the 6.0.x releases (I think this includes future pre-releases) using the RubyGems pessimistic version constraints.
Source
You can run bundle update to update all your gems at once.
If you just want to update a particular gem (such as rails) you can run bundle update rails.
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