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.
Related
If a Rails 6 Gemfile includes ruby "~> 3.0" and the current Ruby version in the project is 3.0.1, how does one upgrade Ruby to the highest current minor release (3.0.2 at this time) without modifying the Gemfile to specify an exact minor release (which would defeat the purpose of the "~> 3.0")?
The specifier ~> has a special meaning, best shown by example. ~> 3.0 is identical to >= 3.0 and < 3.1. So all minor patches are included. See https://bundler.io/gemfile.html.
No need to change your Gemfile just install the gems in the newly installed Ruby version.
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
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.