Ruby

How To Install Ruby 3 With rbenv?

How To Install Ruby 3 With rbenv?
In: Ruby

Naive as I am, I fired up my terminal and gave it a spontaneous shot:

~ rbenv install 3.0.0
ruby-build: definition not found: 3.0.0

See all available versions with `rbenv install --list'.
~
~ # so the investigation began: 🔎🔎🔎
~
~ rbenv install --list
2.5.8
2.6.6
2.7.1
jruby-9.2.13.0
maglev-1.0.0
mruby-2.1.2
rbx-5.0
truffleruby-20.2.0
truffleruby+graalvm-20.2.0
~
~ # WTF?! truffle 20!?!?
A naive shot.

You will most probably encounter this issue when you have rbenv lying around for quite a while already. So the investigation continued:

Where's Ruby 3 in rbenv? 🤔 🔎

rbenv install Ruby 3 on Ubuntu

The sad truth is that my brain was not able to parse the whole terminal output which already poses the solution:

~ rbenv install 3.0.0
ruby-build: definition not found: 3.0.0

See all available versions with `rbenv install --list'.

If the version you need is missing, try upgrading ruby-build:

  git -C ~/.rbenv/plugins/ruby-build pull

~ # Here we go 👆 the crucial hint at the end of the output!
The one moment when "being aware" actually does something.

With the missing information bit, we are now just 2 terminal commands away from victory.

1. Upgrade the rbenv build

~ git -C ~/.rbenv/plugins/ruby-build pull
remote: Enumerating objects: 254, done.
remote: Counting objects: 100% (254/254), done.
remote: Compressing objects: 100% (22/22), done.
... more output ...

2. Install version 3

~ rbenv install 3.0.0
Downloading ruby-3.0.0.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.0.tar.gz
Installing ruby-3.0.0...
... ⏲⏲⏲ ...
... ⏲⏲⏲ ...
... ⏲⏲⏲ ...
Installed ruby-3.0.0 to ~/.rbenv/versions/3.0.0

3. (bonus) Check it's installed

~ rbenv versions
  2.6.6
* 2.7.1 (set by ~/.rbenv/version)
  3.0.0 🎊🎊🎊

And for the sake of completeness and inclusiveness, let's see how it's done on the other operating that exists in this world:

rbenv install Ruby 3 on MacOS

If you installed rbenv via homebrew you'll need to do brew upgrade which will also update your rbenv so that latest stable versions of Ruby should appear in your rbenv.

If you are not using homebrew I don't know what you are doing, and most probably you know what you are doing (but then, why are you here?).


Comments or questions? Just tweet it out to me!


Written by
Rich Steinmetz
Always exploring how we developers can code, learn, communicate and create APIs with more fun. Love to chat about Productocracy. Emoji heavy-user 🤪 And much more but the limit here's 200 chars.
More from Rich Stone Input Output
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Rich Stone Input Output.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.