[Ruby on Rails (RoR)] Use asdf and Ruby plugin to install multiple Ruby versions
asdf and Ruby Plugin
asdf
is a single CLI tool for managing multiple runtime versions. It extend with a simple plugin system to install your favourite language: Dart, Elixir, Flutter, Golang (Go), Java, Node.js, Python, Ruby …
This article is about how to use asdf
and Ruby plugin to install multiple Ruby versions on macOS with the Homebrew package manager.
Prerequisites
-
Xcode Command Line Tools
The Xcode Command Line Tools Package is a small self-contained package available for download separately from Xcode and that allows you to do command line development in macOS which is consists of the macOS SDK and command-line tools such as Clang, which are installed at thisFor more information about installing and using Xcode Command Line Tools, see the Xcode Command Line Tools
-
Homebrew
Homebrew is the Missing Package Manager for macOS (or Linux).For more information about installing and using Homebrew, see the Homebrew - https://brew.sh/.
Installation
Install asdf
1 | Install asdf dependencies |
asdf Ruby Plugin
1 | Install Ruby plugin requirements |
Add to your Shell
Add asdf.sh
to your ~/.zshrc
with:
1 | echo -e "\n. $(brew --prefix asdf)/asdf.sh" >> ${ZDOTDIR:-~}/.zshrc |
Or see Add to your Shell - https://asdf-vm.com/#/core-manage-asdf to learn when you use other shells.
List all Ruby Version
Update Ruby plugin.
1 | asdf plugin update ruby |
List all Ruby versions.
1 | asdf list all ruby |
Install Ruby version
Install a Ruby version manually.
1 | asdf install ruby 2.7.2 |
Migrating from another Ruby version manager
.ruby-version file
asdf uses the .tool-versions for auto-switching between software versions. To ease migration, you can have it read an existing .ruby-version file to find out what version of Ruby should be used. To do this, add the following to $HOME/.asdfrc
:
1 | legacy_version_file = yes |
If you are migrating from version manager that supported fuzzy matching in .ruby-version like rvm or chruby, note that you might have to change .ruby-version to include full version (e.g. change 2.6 to 2.6.1).
FAQs
env: ruby_executable_hooks: No such file or directory
1 | bundle |
Install bundler
gem, then run bundle
against.
1 | gem install bundler |
/.asdf/shims/rails: line 8: /usr/local/Cellar/asdf/0.9.0/libexec/bin/asdf: No such file or directory
1 | rails c |
Run asdf reshime
to update all shims files after moving or deleting ~/.asdf/shims
.
1 | mv ~/.asdf/shims ~/.asdf/shims.0.9.0 |
See bug: Updating asdf did not update version number in shim paths · Issue #1147 · asdf-vm/asdf - https://github.com/asdf-vm/asdf/issues/1147 to learn more.
References
[1] Manage asdf - https://asdf-vm.com/#/core-manage-asdf
[2] asdf-vm/asdf-ruby: Ruby plugin for asdf version manager - https://github.com/asdf-vm/asdf-ruby
[3] Home · rbenv/ruby-build Wiki - https://github.com/rbenv/ruby-build/wiki#suggested-build-environment
[4] Switching to asdf - https://wolfgangrittner.dev/switching-to-asdf-for-ruby/