[Ruby on Rails (RoR)] asdf install Ruby 3.x and Rails 7.0 on macOS

asdf, Ruby 3.x and Rails 7.0

Rails 7.0 has been years in the conceptual making. It’s the fulfillment of a vision to present a truly full-stack approach to web development that tackles both the front- and back-end challenges with equal vigor. An omakase menu that includes everything from the aperitif to the dessert.

And here are some of the many other new features and improvements:

  • At-Work Encryption With Active Record

    Extracted from HEY, we’ve added encrypted attributes to Active Record, so your application can offer at-work encryption in addition to the traditional at-rest and in-transit coverage.

  • Trace Query Origins With Marginalia-Style Tagging

    Almost a decade ago, Marginalia was extracted from Basecamp to trace query origins with SQL comment tagging. Now this external gem has been upstreamed into Active Record as QueryLogs.

  • Asynchronous Query Loading

    When you have a controller action that needs to load two unrelated queries, you can now do it concurrently through Relation#load_async. If you have three complex queries that each take 100ms, you’d have to spend 300ms executing them one by one before. Now you can run them in parallel, spending only a total of 100ms on the set.

  • Zeitwerk Exclusively

    Autoloading in Rails is one of those magical quality of life realities that it’s easy to just take for granted. The trusty old const_missing approach which came with a range of quirks and missing features has finally been replaced exclusively with the Zeitwerk code loader. There are a few upgrade gotchas to be aware of, especially for older applications, but with this upgrade guide you should be on your way in no time

  • A Few Other Highlights

    • ***Spring` is no longer on by default, as faster computers have made it less relevant on anything but the largest applications.

    • ActionController::Live#send_stream makes it easy to stream files that are being generated on-the-fly in controller actions.

    • Parallelized testing will now compare your CPU core count to your test count and scale the parallelization accordingly.

    • Active Storage now uses the faster and more secure libvips as its default variant processor.

Prerequisites

Install Ruby 3.0.3

1
2
3
4
5
6
# Optional
# $ brew upgrade asdf

$ asdf plugin update ruby

$ asdf install ruby 3.0.3

Set Ruby version:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Global
$ asdf global ruby 3.0.3
# $HOME/.tool-versions will then look like:
# ruby 3.0.3
# $ asdf current | grep ruby
# ruby 3.0.3 /Users/cloudolife/.tool-versions

# Local
# $ asdf local ruby 3.0.3
# $PWD/.tool-versions will then look like:
# ruby 3.0.3
# $ asdf current
# ruby 3.0.0 ASDF_RUBY_VERSION environment variable
# $ echo $ASDF_RUBY_VERSION
# 3.0.3

Reshim Ruby version:

1
$ asdf reshim ruby 3.0.3

Check Ruby version:

1
2
$ ruby -v
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-darwin21]

Install Rails

1
2
3
4
5
6
7
# Optional
# $ gem update --system

# $ gem -v
# 3.3.4

$ gem install rails

Check Rails version:

1
2
$ rails -v
Rails 7.0.0

FAQs

Calling DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call DidYouMean.correct_error(error_name, spell_checker)’ instead. or Rails::Engine is abstract, you cannot instantiate it directly.

1
2
3
4
5
6
7
8
9
$ ruby -v
ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin21]

$ rails -v
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Rails 7.0.0

$ rails c # or rails s
/Users/cloudolife/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/railties-7.0.0/lib/rails/railtie.rb:246:in `initialize': Rails::Engine is abstract, you cannot instantiate it directly. (RuntimeError)

ruby 3.1.0p0 is not compatible with Rails 7.0.

See Rails cashes with Ruby 3.1.0 release · Issue #43998 · rails/rails - https://github.com/rails/rails/issues/43998 to learn more.

References

[1] Ruby on Rails — Rails 7.0: Fulfilling a vision - https://rubyonrails.org/2021/12/15/Rails-7-fulfilling-a-vision

[2] How to Use asdf Version Manager on macOS | Peaceful Revolution - https://www.wiserfirst.com/blog/how-to-use-asdf-on-macos/

[3] Manage asdf - https://asdf-vm.com/#/core-manage-asdf

[4] asdf-vm/asdf-ruby: Ruby plugin for asdf version manager - https://github.com/asdf-vm/asdf-ruby

[5] Ruby on Rails 7.0 Release Notes — Ruby on Rails Guides - https://edgeguides.rubyonrails.org/7_0_release_notes.html

[6] Ruby on Rails — A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern. - https://rubyonrails.org/

[7] Ruby Programming Language - https://www.ruby-lang.org/en/