rbenv can't change global ruby version - ruby

My Mac OS X has a default ruby.
$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
I installed rbenv and ruby version 2.1.2.
$ rbenv versions
system
* 2.1.2 (set by /Users/sdw/.rbenv/version)
and I tried to set the global ruby version to 2.1.2, but nothing happened.
$ rbenv global 2.1.2
$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
So I tried to do the same thing with command sudo, but the result is the same.
$ sudo rbenv global 2.1.2
$ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
How can I change my global ruby version to 2.1.2? I never installed rvm or other ruby version managing system.

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

Type $ rbenv version (without "s")
It is possible that output will show a path to the file that is locking the version
2.0.0p451 (set by /path/to/some/directory/.ruby-version)
It is even possible that the file is a hidden file named .ruby-version in your current dir. If its the case just remove that .ruby-version file

Run the below commands before change ruby version:
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
It works for me :)

Uninstall ruby and then install agains:
brew uninstall -f ruby
brew install ruby
Add this two line to you ~/.bash_profile
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
Reopen the console and that's it and run
ruby -v

I realize that I occasionally set local ruby version in home folder, from which I use terminal by default :)
So that's what worked for me:
rm /home/MYUSERNAME/.ruby-version

I had the same issue ("ruby -v" showing the initial version) but reloading (exit/start) my terminal made the trick.
Did you try that first?

If you are installing ruby on rails on ubuntu,and you rbenv doesn't change your ruby version
> rbenv list # This lists all the rbenv versions available
2.6.8
2.7.4
3.0.2
jruby-9.3.1.0
mruby-3.0.0
rbx-5.0
-truffleruby-21.3.0
-truffleruby+graalvm-21.3.0
In my case I need to install ruby 3.0.2
rbenv install 3.0.2
After this also it shows ruby v [2.7.0-]
rbenv global 3.0.2
This will help you change your ruby version.

instead of:
rbenv global 2.7.1
do:
sudo rbenv global 2.7.1

Related

How to set the version of Ruby with rbenv on MacOS?

I was trying to follow the book "Agile Web Development with Rails 5.1" (on MacOS).
I want ruby -v to be 2.4.1.
Currently, ruby -v says ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19].
I want to use rbenv to manage the version of Ruby installed. So I tried rbenv install 2.4.1 then rbenv global 2.4.1. But that still did not change the output of ruby -v. What more do I have to do?
I see that which ruby returns ~/.rubies/ruby-2.6.5/bin/ruby. I can't remember how I installed that version of Ruby - it might have been homebrew.
Okay so
brew install rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
echo 'source ~/.bashrc' >> ~/.bash_profile
rbenv install 2.4.1
rbenv global 2.4.1
rbenv rehash # This is probably what you didn't do, start a new terminal or use rehash
Then try ruby -v and which ruby
You can skip some of the beginning steps in case you have rbenv setup and everything.
I ended up using RVM instead. I'm not sure but I might have had multiple ruby version managers installed when I asked the question.

Rbenv Doesn't Work Trying to Install Latest Version of Ruby

I tried updating my Ruby to the current version 2.6.3 in the terminal. When the installation is complete and I check my version it says it's still 2.3.3.
I've tried re-installing 2 times already, both times have not succeded.
Installed ruby-2.6.3 to /Users/user/.rbenv/versions/2.6.3
$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]
Check the README.md from the project's repo. Your rbenv is not initialized.
Put the following lines into your shell. .bash_profile for Bash, .zshrc for ZSH.
if command -v rbenv &>/dev/null; then
eval "$(rbenv init -)"
fi
After which, restart your shell.
References
Install with Homebrew on macOS

Can't find correct version of ruby with rbenv?

I am working in OSX El Capitan. I have put the following at the end of my ~/.bash_profile, and restarted my terminal:
export RBENV_ROOT=/usr/local/var/rbenv
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
Then I have run the following, without any errors:
brew install rbenv
brew install ruby-build
rbenv install 2.2.2
But when I try ruby --version I see:
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
What am I doing wrong that means I see Ruby 2.0.0 not Ruby 2.2.2?
These are my paths:
~ $ which ruby
/usr/local/var/rbenv/shims/ruby
~ $ which rbenv
/usr/local/bin/rbenv
I think you have to change ruby version by following:
rbenv shell 2.2.2

Ruby -v showing older version when installing with Rbenv 2.2.3

I did
rbenv install 2.2.3
Rbenv Rehash
rbenv Global 2.2.3
however when I check the ruby -v it says
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
And if I try rbenv install again, it says it already exists on
Users/user/.rbenv/versions/2.2.3
For now, adding the following to your shell initialization file (~/.bash_profile for bash users) will fix your problem.
eval "$(rbenv init -)"
Read about what this does here. I recommend reading the official documentation. Bit long, but informative and interesting.
Resolved it by using rvm to install ruby and doing
rvm default ruby

Can't run the correct Ruby version with rbenv

After installing rbenv, I wanted to switch to the correct Ruby version to work on a project, but there seems to be an issue recognizing it.
$ cd project/
$ bundle install
$ Your Ruby version is 2.0.0, but your Gemfile specified 2.1.1
$ rbenv local
$ rbenv: no local version configured for this directory
$ rbenv global
$ 2.1.1
$ ruby --version
$ ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
Am I overlooking something?
There was an issue with my $PATH variable.
This worked for me (in .bash_profile):
export PATH="/usr/local/bin:$PATH"
eval "$(rbenv init -)"

Resources