Install Latest Stable Version of Ruby Using rbenv
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:]]*$/ h;${g;p;}'
One should first update the ruby-build to get the latest version of ruby while install using rbenv..Follow the below steps:
brew reinstall --HEAD ruby-build
(if rbenv is already installed brew may through some error then to move ahead and simplybrew unlink ruby-build
andbrew install --HEAD ruby-build
)
brew upgrade
- and then you could use one of the above approaches suggested above to install automatically the latest version or simply
rbenv install <required latest version>