Install Latest Stable Version of Ruby Using rbenv
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;}'
rbenv not changing ruby version
Check that PATH contains $HOME/.rbenv/shims
and $HOME/.rbenv/bin
$ env | grep PATH
Also check that you have the following in your ~/.bash_profile if using bash or ~/.zshenv if using zsh
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
NOTE:
Make sure it's the last setting in your ~/.bash_profile . I ran into an issue where I installed a program that updated my .bash_profile and reset PATH.
Finally, make sure your $HOME
folder doesn't have a .ruby-version
file that you may have created by accident if you were to have done $ rbenv local <ruby-version>
in your $HOME
folder. Doing $ rbenv global <ruby-version>
modifies the $HOME/.rbenv/version
file, and the existence of a .ruby-version
file in the $HOME
folder would override the version set by $HOME/.rbenv/version
.
From the docs:
Choosing the Ruby Version
When you execute a shim, rbenv determines which Ruby version to use by reading it from the following sources, in this order:
The RBENV_VERSION environment variable, if specified. You can use the rbenv shell command to set this environment variable in your current shell session.
The first .ruby-version file found by searching the directory of the script you are executing and each of its parent directories until reaching the root of your filesystem.
The first .ruby-version file found by searching the current working directory and each of its parent directories until reaching the root of your filesystem. You can modify the .ruby-version file in the current working directory with the rbenv local command.
The global ~/.rbenv/version file. You can modify this file using the rbenv global command. If the global version file is not present, rbenv assumes you want to use the "system" Ruby—i.e. whatever version would be run if rbenv weren't in your path.
Need help installing Ruby 2.7.2 on Mac
You need to install the latest ruby-build
$ brew unlink ruby-build # remove STABLE version
$ brew install --HEAD ruby-build
$ rbenv install -l | grep '2.7.2'
2.7.2
Only latest stable releases for each Ruby implementation are shown.
Use 'rbenv install --list-all' to show all local versions.
How to install ruby on Mac using rbenv?
It looks like you skipped step 2, rbenv init
. rbenv
is tightly integrated with your shell and some shims must be installed by you.
You can debug it with curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
Related Topics
How to Reference a File from Inside of a Gem
How to Resolve "Gpg: Command Not Found" Error During Rvm Installation
Is Require File.Expand_Path(..., _File_) the Best Practice
What's the Opposite of Chr() in Ruby
What Are the Differences Between Rbenv, Rvm, and Chruby
Rails - Invalid Authenticity Token After Deploy
Mongo - Ruby Connection Problem
Could Not Find a Valid Gem 'Rails' (>= 0) in Any Repository
Ruby SASS, Unable to Resolve Dependancies
How to Globally Configure Rspec to Keep the '--Color' and '--Format Specdoc' Options Turned On
Sort Array Returned by Activerecord by Date (Or Any Other Column)
Cannot Access Local Sinatra Server from Another Computer on Same Network
Error Installing Gem Capybara-Webkit