rbenv not changing ruby version

2019-01-02 19:30发布

I installed rbenv according to the github directions. I am running OSX but I have tried this on a Ubuntu 12.04 VM and got the same results. The following is what i get in my terminal when I try to change ruby versions:

rbenv versions
* 1.9.3-p0 (set by /Users/user/.rbenv/version)
1.9.3-p125

rbenv global
1.9.3-p0

rbenv rehash

ruby -v
ruby 1.8.7 (2011-12-28 patchlevel 357) [universal-darwin11.0]

which ruby
/usr/bin/ruby

Anyone have any ideas as to why rbenv isn't switching the ruby version like it thinks it is? Also there is no .rbenv file in the local directory that would be causing the ruby version to default to 1.8.7

rbenv local
rbenv: no local version configured for this directory

标签: ruby rbenv
19条回答
有味是清欢
2楼-- · 2019-01-02 19:43

This may be an old question, but Google led me here and, for posterity sake, thought I'd share.

My problem persisted after many of the recommended solutions above. Like the OP, I installed rbenv and then a ruby version, but my laptop defaulted to system. What I had overlooked was that when I ran:

[~/.rbenv] $ rbenv versions
* system (set by /Users/alphadogg/.rbenv/version)
  2.0.0-p247

IOW, it was still defaulting to system. A quick

[~/.rbenv] $ rbenv local 2.0.0-p247

switched it to the new version.

查看更多
情到深处是孤独
3楼-- · 2019-01-02 19:45

I came to the same problem. Fixed this by run the "rbenv global" command with "sudo". I think it was something permission problem.

update: I finally found the solution. There was one same file "version" on my mac, which is under "/usr/local/Cellar/rbenv/0.3.0/". I think it was created by mistake occasionally. you should remove it.

查看更多
千与千寻千般痛.
4楼-- · 2019-01-02 19:46

Run this command

Add rbenv to bash so that it loads every time you open a terminal

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile

this will solve your problem Reference

查看更多
旧时光的记忆
5楼-- · 2019-01-02 19:46

I had the same problem, but caused by Homebrew:

[~]$ rbenv version
2.3.0 (set by /Users/user/.rbenv/version)
[~]$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
[~]$ which ruby
/usr/local/bin/ruby

Somehow I had installed Ruby via Homebrew too, and the Homebrew path was ahead of the rbenv path in my $PATH. Running brew uninstall ruby fixed it for me.

查看更多
路过你的时光
6楼-- · 2019-01-02 19:50

rbenv help shell

"Sets a shell-specific Ruby version by setting the 'RBENV_VERSION' environment variable in your shell. This version overrides localapplication-specific versions and the global version. should be a string matching a Ruby version known to rbenv.The special version string 'system' will use your default system Ruby. Run rbenv versions' for a list of available Ruby versions."

Provided rbenv was installed correctly, ruby -v will correspond to

rbenv shell 1.9.3-p125

查看更多
一个人的天荒地老
7楼-- · 2019-01-02 19:50

run:

rbenv init

After I ran that, when i set my local rbenv version:

rbenv local 2.4.0

then my ruby -v and my rbenv local versions coincided.

Note: You might also want to exit the directory you're in and then go back into it, i've noticed that was necessary for me in order to get things to work.

查看更多
登录 后发表回答