Can't find correct version of ruby with rbenv? - ruby

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

Related

rbenv and managing ruby versions not working. Need 2.5.1

I'm on Mac OS 10.14.6 (Mojave).
I'm trying to switch to ruby version 2.5.1 with rbenv, but i'm getting no errors or any luck changing... I also tried Switch to a different version of ruby using homebrew, but had no luck.
jj:project me$ rbenv -v
rbenv 1.1.2
jj:project me$ brew -v
Homebrew 2.2.14
Homebrew/homebrew-core (git revision ffa73; last commit 2020-05-03)
Homebrew/homebrew-cask (git revision f3b530; last commit 2020-05-03)
jj:project me$ ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
jj:project me$ rbenv install 2.5.1
jj:project me$ rbenv local 2.5.1
rbenv: version `2.5.1' not installed
jj:project me$ rbenv install -l
...
2.4.10
2.5.0-dev
2.5.0-preview1
2.5.0-rc1
2.5.0
2.5.1
2.5.2
...
I've tried rbenv uninstall 2.5.1 and it says rbenv: version2.5.1' not installed`. I updated brew and ruby-build too. Xcode looks fine... not sure what else to try...
Seems i can even run rbenv install 99 and got no errors. Same with rbenv install gibberish
Eff...
Thanks in advance
Did you add eval "$(rbenv init -)” to ~/.bashrc ?
If you didn’t, you can try add this and exec source ~/.bashrc.

rbenv working but ruby version not changing

❯ rbenv version
system (set by /Users/eric.nguyen/.rbenv/version)
❯ rbenv local 2.4.2
❯ gem install bundler
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
❯ rbenv global 2.4.2
❯ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
❯ rbenv version
2.4.2 (set by /Users/eric.nguyen/.ruby-version)
❯ gem install bundler
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
❯ gem -v
2.0.14.1
Ruby version is is still 2.0.0p648
I'm on macOS Sierra 10.12.6.
I've done everything mentioned here
I've done:
rbenv rehash
put eval "$(rbenv init -)" in my .zshrc and source ~/.zshrc
put $HOME/.rbenv/shims into $PATH (/Users/eric.nguyen/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/eric.nguyen/Library/Android/sdk/tools:/Users/eric.nguyen/Library/Android/sdk/platform-tools:/Users/eric.nguyen/.rbenv/shims)
But it still doesn't change ruby version.
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
You always need to run rbenv rehash after you install a new ruby version using rbenv and also when you install a gem that has a command line options

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 -)"

rbenv can't change global ruby version

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

rbenv on OS X Mavericks not work

I try to change my ruby version and I get this on my terminal :
Cristians-MacBook-Air% rbenv versions
system
1.9.3-p448
2.0.0-p247
* 2.1.0 (set by /Users/Cristian/.ruby-version)
Cristians-MacBook-Air% ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]
rbenv say 2.1.0 is active but then I run ruby -v my active ruby version is other 2.1.0p0
In my .bash_profile :
eval "$(rbenv init -)"
export PATH='brew --prefix rbenv'/shims:'brew --prefix rbenv'/bin:$PATH
I am not using ZSH yet.
Some idea??..
Thanks!!

Resources