Can't run the correct Ruby version with rbenv - ruby

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

Related

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

setting local ruby version with rbenv not working?

I cant really understand the problem here:
➜ myflixx git:(master) ✗ rbenv local
2.1.1
➜ myflixx git:(master) ✗ rails -v
Your Ruby version is 2.0.0, but your Gemfile specified 2.1.1
➜ myflixx git:(master) ✗ rake -T
Your Ruby version is 2.0.0, but your Gemfile specified 2.1.1
Why is it complaining about Ruby version 2.0.0 when I've already set the local version (with rbenv) to 2.1.1?
Is it something that I'm missing? thanks for your time!
This makes sure your paths are correctly set.
In Bashrc or equivalent:
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
Install everything and locally define what ruby version to use for the app.
brew install rbenv ruby-build
rbenv install <ruby-version>
rbenv rehash
rbenv local <ruby-version>
Restart terminal or source the bashrc.

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

Your Ruby version is 2.1.0, but your Gemfile specified 2.0.0

In my Gemfile I specified ruby version 2.0.0:
ruby '2.0.0'
But my console tells me I have 2.1.0dev:
$ ruby -v
ruby 2.1.0dev (2013-09-16 trunk 42951) [x86_64-darwin12.4.0]
I am using rbenv and it tells my I don't have 2.1.0 installed,
$ rbenv versions
system
* 2.0.0-dev
Bundle update or bundle install says:
"Your Ruby version is 2.1.0, but your Gemfile specified 2.0.0"
but using 'rbenv local 2.0.0-dev' leaves me with ruby 2.1.0dev again. Furthermore:
$ rbenv global
2.0.0-dev
$ cat ~/.bash_profile:
export PATH="$HOME/.rbenv/bin:$PATH"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
As far as I know, 2.1.0dev doesn't even exist yet.
How can i get ruby 2.0.0 selected?
You may need to update your version of ruby-build to make sure you have the update where ruby-2.0.0-dev switched to follow the ruby_2_0_0 branch.
Try running ruby-build --version and make sure it's one of these (or later):
v20130907
v20130901
v20130806
v20130628
v20130518
v20130514
v20130501
v20130408
v20130227
v20130226
v20130225
If not, run brew upgrade ruby-build.
Go to your Gemfile and change the description there
I just got the same problem and couldn't find a "working" solution. So I made my own.
source 'https://rubygems.org'
ruby '2.0.0' #Change this one to this '2.1.0'
gem 'rails', '4.0.3'

Resources