OSX not using latest Ruby version

僤鯓⒐⒋嵵緔 提交于 2019-12-11 00:56:37

问题


When I try to run a ruby command in terminal I get an error:

Ruby >= 2.1.9 required to run app (You have 2.0.0)

When I try

brew upgrade ruby

I get

Error: ruby 2.3.1 already installed

Previously I tried installing ruby with rvm

curl -sSL https://get.rvm.io | bash -s stable --ruby

Maybe I have two different versions of ruby running?

How can I get my system to use the latest version of ruby?

EDIT: Definitely two versions installed

/usr/local/bin/ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
ruby -v
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

My $PATH seems correct?

-bash: /usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin: No such file or directory

EDIT2 specifying the full path to the correct version of ruby:

/usr/local/bin/ruby app.rb
/usr/local/bin/ruby: No such file or directory -- app (LoadError)

回答1:


In the simplest cases, you can just specify the fully-qualified PATH to your Homebrew-installed Ruby. For example:

/usr/local/bin/ruby /path/to/foo.rb

However, if you need to require gems or libraries, you need to step up your game with a Ruby version manager such as chruby, rvm, or rbenv. You should never replace the system ruby, and managing all the environments variables, gems, and so forth that Ruby needs without a version manager is outside the scope of a reasonable Stack Overflow question.




回答2:


You have installed the homebrew version 2.3.1 of Ruby, but you are not using it because you haven't set your PATH correctly.

Try using the one homebrew installed for you by adding /usr/local/bin to the start of you PATH, or by running:

/usr/local/bin/ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]

I guess if you use the Apple-supplied Ruby in /usr/bin you will get:

/usr/bin/ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]



回答3:


You should uninstall ruby from brew and just use rvm.




回答4:


If you have multiple version installed than you can use rvm to make ruby 2.3.1 your default: rvm --default use 2.1.1



来源:https://stackoverflow.com/questions/39397874/osx-not-using-latest-ruby-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!