如何切换到使用 Homebrew 安装的 ruby 1.9.3?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8730676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I switch to ruby 1.9.3 installed using Homebrew?
提问by Alexey Zakharov
回答by Matthew Rudy
I suggest you take a look at rvm.
You can then set it as default with rvm use 1.9.3 --default
我建议你看看rvm。然后您可以将其设置为默认值rvm use 1.9.3 --default
But if you are happy with your homebrew install.
但是,如果您对自制软件的安装感到满意。
Then just change the precedence of directories in the PATH
然后只需更改目录中的优先级 PATH
Here is my /etc/paths
这是我的 /etc/paths
# homebrews should always take precedence
/usr/local/bin
# the default stack
/usr/bin
/bin
/usr/sbin
/sbin
This is important generally for homebrew, else the system version of git, ruby, pg_admin,... will all be used instead of the brew version.
这对于自制软件来说通常很重要,否则将使用系统版本的 git、ruby、pg_admin... 代替 brew 版本。
if you say which -a rubyyou'll see all the installed rubies, and the precedence in the PATH
如果你说which -a ruby你会看到所有安装的红宝石,以及优先级PATH
eg.
例如。
$ which -a ruby
/Users/matthew/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
/Users/matthew/.rvm/bin/ruby
/usr/bin/ruby
更新:我现在认为你不应该改变
/etc/paths/etc/pathsInstead you need to check which of .profile, .bashrc, or .bash_loginis being loaded in your shell, and just add /usr/local/binto your path.
相反,你需要检查哪.profile,.bashrc或.bash_login正在在你的shell加载,只需添加/usr/local/bin到您的路径。
For me, I only have a .profile. You can create that file if none of those files already exist in your home directory.
对我来说,我只有一个.profile. 如果您的主目录中不存在这些文件,您可以创建该文件。
# homebrews should always take precedence
export PATH=/usr/local/bin:$PATH
回答by Craig Wayne
SHORT ANSWER:
简短回答:
after installing ruby via homebrew just do this:
通过自制软件安装 ruby 后,只需执行以下操作:
brew link --overwrite ruby
and restart or reopen your Terminal
并重新启动或重新打开您的终端
LONG ANSWER
长答案
So I did a normal install of ruby using homebrew
所以我使用自制软件进行了正常的 ruby 安装
brew install ruby
that installed fine BUT it was still using the system's default ruby. which I verified by doing:
安装得很好,但它仍在使用系统的默认红宝石。我通过以下方式验证:
which ruby
#/usr/bin/ruby
So as per Matthew Rudy's suggestion, I checked the order of my /etc/paths, and all was good.
所以按照 Matthew Rudy 的建议,我检查了我的 /etc/paths 的顺序,一切都很好。
Then I decided to do:
然后我决定这样做:
which -a ruby
#/usr/bin/ruby
#usr/local/bin/ruby
so nothing was broken as such. tried to reinstall ruby again using the homebrew method, and then i found it.
所以没有任何东西被破坏。尝试使用自制方法再次重新安装ruby,然后我找到了它。
Homebrew mentioned:
家酿提到:
Warning: ruby-2.3.1 already installed, it's just not linked
so had to do:
所以必须这样做:
brew link --overwrite ruby
回答by Francis Kim
If you'd like to use homebrew to install 1.9.3, you can follow these steps:
如果您想使用 homebrew 安装 1.9.3,您可以按照以下步骤操作:
$ brew update
$ brew install rbenv
$ brew install ruby-build
Once you have rbenv and ruby-build installed, you can run the following command to get Ruby 1.9.3 installed.
安装 rbenv 和 ruby-build 后,您可以运行以下命令来安装 Ruby 1.9.3。
$ rbenv install 1.9.3-p125
Now if you'd like to use 1.9.3 by default, you can run the following command:
现在,如果您想默认使用 1.9.3,可以运行以下命令:
$ rbenv global 1.9.3-p125
回答by Andrii Chernenko
I had similar situation. I installed ruby using Homebrew. which -a rubygave me the following output:
我有类似的情况。我使用 Homebrew 安装了 ruby。which -a ruby给了我以下输出:
#usr/local/bin/ruby
#/usr/bin/ruby
Which means that newly installed version should have been used, but ruby --versionstill returned the old system version.
这意味着应该使用新安装的版本,但ruby --version仍然返回旧的系统版本。
I quit terminal (Cmd+Q), and after restart ruby --versionreturned the correct version. So make sure you restart terminal after installing before trying any other (potentially unnecessary) fixes.
我退出终端(Cmd+Q),重启后ruby --version返回正确的版本。因此,在尝试任何其他(可能不必要的)修复之前,请确保在安装后重新启动终端。
回答by Richard Lin
SHORT:Do note what you want to change it for.
简短:请注意您要更改它的目的。
If you're on OS X and trying to use Ruby for something like Jekyll, then don't use homebrew because that's what Apple is using for Ruby for and it might not be good to use if you're not sure what you're doing. Instead, use rbenv or RVM.
如果您使用的是 OS X 并尝试将 Ruby 用于 Jekyll 之类的东西,那么请不要使用自制软件,因为这是 Apple 用于 Ruby 的用途,如果您不确定自己的用途,可能不太适合使用正在做。相反,请使用 rbenv 或 RVM。
LESS SHORT:I was trying to switch from the default version to an updated version (from 2.0) to use Jekyll because it required Ruby version 2.2.5 and above. I updated it and version 2.5 was installed, but when I checked "ruby -v", it was still 2.0. Once I finally got around to changing the default version, I wasn't able to install the package I needed because I didn't have write permission. For example, if you come across something like this, then you probably are having the same problem
更短:我试图从默认版本切换到更新版本(从 2.0)以使用 Jekyll,因为它需要 Ruby 版本 2.2.5 及更高版本。我更新了它并安装了 2.5 版,但是当我检查“ruby -v”时,它仍然是 2.0。一旦我终于开始更改默认版本,我就无法安装我需要的包,因为我没有写权限。例如,如果您遇到这样的事情,那么您可能遇到了同样的问题
$ gem install jekyll bundler
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
回答by Robert
In OSX you can change the path using:
在 OSX 中,您可以使用以下方法更改路径:
sudo nano /etc/paths
须藤纳米 /etc/paths
And then add a path or change the order.
然后添加路径或更改顺序。
回答by Bn Mk
Just as an alternative approach for anyone else looking for an answer to this - you can set an alias in your .bash_profile e.g
就像其他人寻找答案的替代方法一样 - 您可以在 .bash_profile 中设置别名,例如
ruby="/usr/local/bin/ruby"
this is how i got around the issue
这就是我解决这个问题的方法

