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
Related
I have the following environment setup
OS: macOS Catalina 10.15.7
Zsh: 5.8
Neovim: 0.4.4
rbenv: 1.1.2
$ rbenv local
2.7.1
$ rbenv global
2.7.1
$ /usr/bin/ruby --version
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
RBENV_VERSION is not set. rbenv-doctor script also fine. Above all the facts, I assumed my rbenv setup is working.
When I am in neovim,
:echo has('ruby')
1
:ruby puts RUBY_VERSION
2.6.3
It should have been 2.7.1 but 2.6.3 (system ruby provided by macOS)
I have started with nvim -u NORC and still getting the same.
What should I check next to make NeoVim picks up rbenv specified ruby?
It cannot be reproduced in another (clean) account.
It was caused by messed up rbenv environment.
rudimentary neovim-ruby-host remained in old ruby version (found out by rbenv whence neovim-ruby-host showing unused ruby version)
rbenv shim (specifically gem) using system provided gem. (rmed the shims and rbenv rehashed)
rbenv doctor was not enough for the troubleshooting. The followings helped me find the cause
gem env and gem env home: showed I was using system provided gem executable
rbenv rehash: removed the staled shims and recreated them
rbenv which neovim-ruby-host: showed actual path of neovim-ruby-host
rbenv whence neovim-ruby-host: showed ruby versions providing the command (in my case incorrect one)
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.
I have gone about the recommended way of installing a new version of Ruby on Mac OS X: Homebrew, and rvm. I ran rbenv to install Ruby 2.3.3, and selected it as the preferred version by using "rbenv global 2.3.3". The problem I am having is that there is currently a 2.0.0 version installed at /usr/bin/ruby, and for some crazy reason I am unable to remove it.
$ rbenv global
2.3.3
$ which ruby
/usr/bin/ruby
$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
$ ~/.rbenv/versions/2.3.3/bin/ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
sudo rm -rf /usr/bin/ruby
Password:
rm: /usr/bin/ruby: Operation not permitted
Argh!! Please help.
The problem is not your system Ruby, the problem is you probably didn't follow the rbenv installation instructions completely correctly.
The reason the system Ruby is located before your rbenv Ruby, is because your PATH has not been properly updated.
This explains why that is important:
https://github.com/rbenv/rbenv#understanding-path
To set up your PATH correctly you can read and complete steps 2-4 here:
https://github.com/rbenv/rbenv#basic-github-checkout
I was reading through some of the rbenv documentation to try to wrap mind mind around how it works and I read the following:
rbenv works by inserting a directory of shims at the front of your
PATH:
~/.rbenv/shims:/usr/local/bin:/usr/bin:/bin Through a process called
rehashing, rbenv maintains shims in that directory to match every Ruby
command across every installed version of Ruby—irb, gem, rake, rails,
ruby, and so on.
I'm currently able to use rbenv successfully to switch between different versions of ruby:
~/.rbenv/versions ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin15.0]
~/.rbenv/versions rbenv versions
system
* 2.1.5 (set by /Users/max/.rbenv/version)
2.2.3
~/.rbenv/versions rbenv global 2.2.3
~/.rbenv/versions rbenv rehash
~/.rbenv/versions ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
~/.rbenv/versions rbenv global 2.1.5
~/.rbenv/versions rbenv rehash
~/.rbenv/versions ruby -v
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin15.0]
But then when I looked inside my ~/.zshrc file I found the following:
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$HOME/.rbenv/shims:$HOME/.rbenv/bin"
which seems like rbenv hasn't prepended anything and it's actually appended which according to the documentation makes it seem like it wouldn't work and my system would look into /usr/bin and find my system ruby executable and run it instead of the ones that I have inside /Users/max/.rbenv/versions. But that's obviously not what is happening, so I'm wondering what's going on here? Am I missing something?
EDIT: I was just digging around more in my .zshrc file and I found this at the very bottom, probably from when I was trying to figure out how to get rbenv working the first time:
# Fix to rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
Is this the line that is "prepending" as the documentation says? So it that case could is this mention of .rbenv in export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$HOME/.rbenv/shims:$HOME/.rbenv/bin" redundant?
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