Simple solution (directly installs latest stable version):
rbenv install $(rbenv install -l | grep -v - | tail -1)
Explanation:
rbenv install -l | grep -v - | tail -1
Filters out all versions that contain a hyphen -, which is all non-MRI versions and prerelease MRI versions. Then selects the last one, guaranteed to be the highest because ruby-build output is already sorted by version number ascending.
Simple solution (directly installs latest stable version):
rbenv install $(rbenv install -l | grep -v - | tail -1)
Explanation:
rbenv install -l | grep -v - | tail -1
Filters out all versions that contain a hyphen -, which is all non-MRI versions and prerelease MRI versions. Then selects the last one, guaranteed to be the highest because ruby-build output is already sorted by version number ascending.
rbenv install -l | awk -F '.' '
/^[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+[[:space:]]*$/ {
if ( ($1 * 100 + $2) * 100 + $3 > Max ) {
Max = ($1 * 100 + $2) * 100 + $3
Version=$0
}
}
END { print Version }'
- Take the biggest version (sorted order or not)
If list is sorted a simpler sed (posix version) is enough
rbenv install -l | sed -n '/^[[:space:]]*[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}[[:space:]]*
{g;p;}'
rbenv not showing the available ruby versions - Stack Overflow
Need to install Ruby 2.7.7 with rbenv but rbenv doesn't list it. Help?
How can I install an Rbenv version specified by a .ruby-version file
Can't install latest Ruby on OS Sonoma due to 'no permissions'
Videos
Are you asking what the output of that command means? I'm looking at the rbenv documentation, and I think it indicates that rbenv only knows of one version of ruby - the version that came installed with your system.
Edit: If that's not the answer you were looking for, can you tell us what you expected to see? Did you have other versions installed on that machine?
Edit 2: If you want to see a list of versions you can install onto your machine, but aren't installed yet, run:
rbenv install --list
Here is more documentation for this command. This will help!
If you have tried both rbenv install --list and ruby-build --definitions and still can't see the latest Ruby versions on the list, then you need to upgrade ruby-build because that is what rbenv uses to "know" the available versions.
For example, assuming you use Mac OS X and installed ruby-build using Homebrew, you can update ruby-build by invoking:
brew upgrade ruby-build
Now, try listing the available versions again, and you should see the latest ones there.
Edit:
The ruby-build wiki lists a couple of ways of updating it, namely the above one using Homebrew and another one where it is installed as a plugin to rbenv:
cd "$(rbenv root)"/plugins/ruby-build && git pull
The why:
-
A Rails app stuck on Rails 4 (which I don't think supports Ruby 3.x)
-
Heroku-18 stack EOL approaching
-
Heroku-20 supports Ruby 2.7.7
-
Trying to extend the maintainability window of the app by moving it to Heroku-20 stack - while working on upgrading the app.
But, rbenv --list-all does not list 2.7.7 - the mri rubies list stops at 2.7.5 (as of Feb 1 2023).
rbenv on M1 hardware.
How can I install 2.7.7 via rbenv?