Installing Ruby using ASDF in macOS
I received a new MacBook Pro from Edge Payments Technologies and spent the last couple of hours configuring the machine. I have always relied on RVM to install and manage Ruby versions. This time I decided to use ASDF. The plan is to use one version manager to manage projects that use Ruby, Elixir and Node JS.
I assume you have installed Homebrew, the missing package manager for macOS.
Installing ASDF
Let's make sure we have all the dependencies installed.
brew install coreutils curl git
Then we can proceed to install ASDF.
brew install asdf
Since Catalina, ZSH is the default shell. Let's add the following line to ~/.zprofile
. You can also add it to ~/.zshrc
or any script that gets sourced when the terminal is launched.
. $(brew --prefix)/opt/asdf/libexec/asdf.sh
Install Ruby
We start by installing the Ruby plugin.
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git
Then we can install ruby using and setting it as the global Ruby version.
asdf install ruby 3.2.0
asdf global ruby 3.2.0
Reload ZSH, using exec zsh
, and your Ruby will be available in your shell.
❯ ruby -v
ruby 3.2.0 (2022-12-25 revision a528908271) [arm64-darwin21]
Now you can install any Ruby gem.
gem install rails
Conclusion
Depending on the team, RVM and Rbenv have been the go-to method for many teams to install and manage Ruby versions. ASDF has enabled us to manage multiple runtimes using a single tool. While it is the first time I am using ASDF for Ruby, I have previously used it with Elixir/Erlang and Node JS. While I greatly respect RVM, I think the time has come for ASDF to rule the future of runtimes.
About the Author
Ziyan Junaideen -
Ziyan is an expert Ruby on Rails web developer with 8 years of experience specializing in SaaS applications. He spends his free time he writes blogs, drawing on his iPad, shoots photos.