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.
Rbenv not using the correct version
Try with this.
In your rails project folder check the presence of .ruby-version
file and put inside the same ruby version specified into Gemfile.
(if this file is not present, create it.)
~/your-rails-project/.ruby-version file:
2.5.3
~/your-rails-project/Gemfile file:
source 'https://rubygems.org'
ruby '2.5.3'
...
Then install that version with rbenv:
$ rbenv install 2.5.3
$ rbenv rehash
$ rbenv local 2.5.3
$ rbenv global 2.5.3
Now check that you are using the right version with:
$ ruby -v
rbenv can't change global ruby version
Did you add the following lines to your ~/.bash_profile
?
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
See: https://github.com/sstephenson/rbenv#installation
rbenv working but ruby version not changing
Restarting my computer resolve the issue.
❯ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]
❯ gem -v
2.6.13
I want to change ruby version by rbenv, but I can't reset my 'which ruby'
Ensure there is something like this in your ~/.zshrc
file:
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
Related Topics
Error: While Executing Gem ... (Gem::Filepermissionerror)
Why Use Ruby'S Attr_Accessor, Attr_Reader and Attr_Writer
Oo Design in Rails: Where to Put Stuff
Using Sinatra For Larger Projects Via Multiple Files
What Are the Ruby File.Open Modes and Options
Converting Camel Case to Underscore Case in Ruby
Is It Good Style to Explicitly Return in Ruby
How to Uninstall Ruby on Ubuntu
How to Seed a Database in Rails
Validation for Non-Negative Integers and Decimal Values
How to Write a Switch Statement in Ruby
Do..End VS Curly Braces For Blocks in Ruby
How to Download a File from a Url and Save It in Rails