31
Wrestling with Rails Installation
TL; DR: Rails versions can be manually changed in the Gemfile and using the default (latest) version of Ruby is fine.
For posterity, I felt like sharing the trouble I briefly had with installing Rails on Linux:
I am trying to follow the steps in the book Agile Web Development with Rails 6, but without a VM because my local machine isn't very fast.
The book says to ensure we are using Ruby 2.6.5 with Rails 6.0.1 by running rbenv local 2.6.5
or rbenv global 2.6.5
and start with rails _6.0.1_ new demo
. I do this but then running bin/rails about
tells me that I've got Rails 6.0.4. with Ruby 2.7.4 instead!
Following the book's instructions, I used rbenv local 2.6.5
then rails _6.0.1_ new demo
and the Gemfile showed
Rails version 6.0.4.1
Ruby version ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux-gnu]
I then tried to follow the steps from this Stackoverflow question and from this blog post, seemingly without success.
I check that I'm on the correct version of Ruby and Rails:
┌─[wasim@parrot]─[~/dev/new/demo]
└──╼ $rbenv local
2.6.5
┌─[wasim@parrot]─[~/dev/new/demo]
└──╼ $cat Gemfile
source 'https://rubygems.org'
gem 'rails', '6.0.1'
┌─[wasim@parrot]─[~/dev/new/demo]
└──╼ $bundle exec rails -v
Rails 6.0.1
but after running bundle install
and then bundle exec rails new . --force --skip-bundle
, I get this:
┌─[wasim@parrot]─[~/dev/new/demo]
└──╼ $bundle exec rails -v
Rails 6.0.1
┌─[wasim@parrot]─[~/dev/new/demo]
└──╼ $cat Gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.4'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.1'
From here, I tried removing ~>
from the version number and running bundle install
, which outputs Using rails 6.0.1
, so it seems like it should work. Running bin/rails about does indeed tell me that we are finally on rails 6.0.1, but Ruby is on version 2.7.4 now!
If I try the same approach to change the Ruby version number in the Gemfile and run bundle update
, an error message tells me that my versions conflict and it won't proceed.
So I can get the correct version of Rails with one approach but it doesn't give me the correct version of Ruby, and if I follow the book's instructions then both are wrong.
At this point, I was about to post a question to StackOverflow asking if this is even worth troubleshooting or should I just use a clean VM or Docker image?
Instead, I re-read the instructions from the book and while it is expected that we use the older version of Rails, it's fine to use the default (latest) version of Ruby.
So by following either approach and then modifying just the version of rails (not the Ruby version) in the Gemfile, we're already done!
I run bin/rails server
and everything works. Maybe this will be helpful to someone else starting out with Ruby on Rails.
31