I want to install the latest stable version of Ruby available with rbenv. This feature won\'t be happening in rbenv itself.
When I run the command rbenv instal
I would much rather do it in Ruby than in bash.
versions = `rbenv install -l`
versions.split("\s").select{|v| v.match( /^\d*\.\d*\.\d*$/ )}.last
After quite a bit of trial-and-error I figured out a way to grab the latest stable version from this list. This isn't perfect as it just grabs the correct pattern and the last version of it, but it should get the job done. It will work as long as the versions are in order.
This will produce 2.2.2
rbenv install -l | grep -P "^ [[:digit:]]\.[[:digit:]]\.[[:digit:]]$" | tail -1
We can plug that result into rbenv install
like this:
rbenv install $(rbenv install -l | grep -P "^ [[:digit:]]\.[[:digit:]]\.[[:digit:]]$" | tail -1)
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.
Mine is similar to Anonymous's answer (but shorter because I'm using \d).
rbenv install -l| grep -P "\s2.*(\.|\d)\d$" | tail -1
I wanted to specify the latest jruby, which is why I used a "2", so I can replace the 2 with "jruby":
rbenv install -l| grep -P "\sjruby.*(\.|\d)\d$"|tail -1
You can replace jruby with other strings to get different types of ruby, e.g. rbx, mruby.
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 }'
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 simply
brew unlink ruby-build
and brew install --HEAD ruby-build
)brew upgrade
rbenv install <required latest version>