安装 Ruby gems 不适用于 Homebrew
我通过 sudo gem install ...
安装的 gem 无法执行(我收到 command not find
)。
它们似乎安装到 Brew 的安装目录 /usr/local/Cellar/
中(此外,/Library/Ruby/
中的 gem 也不起作用)。我还需要做些什么才能使 gems 可执行吗?我在 Mac OS X 10.6 上使用 Zsh,在 Brew 中使用 Ruby v1.8。
编辑:它现在似乎正在工作。我刚出去几个小时,回来再试一次。
The gems I install via sudo gem install ...
can't be executed (I get a command not found
).
They seem to install into /usr/local/Cellar/
which is Brew's install directory (also, the gems in /Library/Ruby/
don't work either). Is there anything else I need to do to make the gems executable? I'm using Zsh on Mac OS X 10.6 with Ruby v1.8 for the one in Brew.
EDIT: It seems to be working now. I just went out for a few hours and came back to try it again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
自制的很不错。然而,与
brew
和npm
不同,gem
不会自动在/usr/local/bin
中创建别名。解决方案
我采用了一种非常简单的方法(截至 2020 年 3 月):
将其添加到您的
.bashrc
(或.bash_profile
、.zshrc
、 ETC。)。就是这样!现在,所有 Ruby bin 和已安装的 gem 都可以从您的 shell 中获得!
在旧版本的 Homebrew 中(2017 年之前),Ruby 2 有一个名为
ruby20
的单独包,您可以使用以下代码片段来代替:此行是当时唯一需要的行。但是,在 Ruby 2.1 中,gems 被移动到一个单独的目录中。不再位于
/usr/local/opt/ruby/bin
下,而是位于/usr/local/lib/ruby/gems/2.0.0/bin
下(其中“ 2.0.0”是用于 Gem 目的的最后一个主要 Ruby 版本)。工作原理
Homebrew 会跟踪安装包的位置,并为您维护一个指向那里的符号链接。
实际上,将
/usr/local/opt/ruby
添加到PATH
与以下内容相同:除了,这个长版本硬编码了当前安装的 Ruby 版本,并且将停止工作下次升级 Ruby 时。
至于 Gem,以下命令将告诉您 Gem 将新包添加到的确切目录:
工具
这些工具旨在自动在 Homebrew 和 Gem 之间建立桥梁:
josh/brew-gem(不再存在)indirect/brewbygems(未维护)我没有使用过这些,但它们可能对你有用。
Homebrew is nice. However unlike
brew
andnpm
,gem
does not make aliases in/usr/local/bin
automatically.Solution
I went for a very simple approach (as of March 2020):
Add this to your
.bashrc
(or.bash_profile
,.zshrc
, etc.).That's it! Now all Ruby bins and installed gems will be available from your shell!
In older versions of Homebrew (before 2017), there was a separate package for Ruby 2 called
ruby20
, for which you'd use the following snippet instead:This line was the only line needed at the time. But, in Ruby 2.1 the gems got moved to a separate directory. No longer under
/usr/local/opt/ruby/bin
, but instead at/usr/local/lib/ruby/gems/2.0.0/bin
(where "2.0.0" is the last major Ruby version for Gem's purposes).How it works
Homebrew keeps track of where it installed a package, and maintains a symbolic link for you that points there.
Effectively, adding
/usr/local/opt/ruby
toPATH
is the same as the following:Except, this long version hardcodes the currently installed version of Ruby and would stop working next time you upgrade Ruby.
As for Gem, the following command will tell you the exact directory Gem adds new packages to:
Tools
These tools were meant to automatically bridge between Homebrew and Gem:
josh/brew-gem(no longer exists)indirect/brewbygems(unmaintained)I haven't used these but they might work for you.
brew 取消链接 ruby; brew link ruby
可能会将符号链接添加到/usr/local/bin/
:brew --prefix ruby
仍然很慢,但您也可以只添加 < code>/usr/local/opt/ruby/bin 到路径。brew unlink ruby; brew link ruby
might add symlinks to/usr/local/bin/
:brew --prefix ruby
is still pretty slow, but you could also just add/usr/local/opt/ruby/bin
to the path.使用蒂莫的答案中的信息,我得到了这个:
适用于 Homebrew,适用于单独的 gems 目录,并且不不要硬编码 Ruby 版本。
Using the info in Timo's answer, I've got this:
Works for Homebrew, works for the separate gems directory, and doesn't hardcode a Ruby version.
我喜欢自酿啤酒。可能有更好的方法来做到这一点,但如果你运行:
这将打印出所有相关路径的漂亮列表。查找标有
EXECUTABLE DIRECTORY
的目录。这就是您要添加到路径中的路径。就我而言,它是/usr/local/Cellar/ruby/1.9.3-p362/bin/ruby
但我想它会随着 Ruby 的新版本而改变。我使用
/bin/bash
作为我的 shell,但将其添加到路径的过程应该与名称差不多。我使用 TextWrangler(通过命令行工具)编辑我的
.profile
文件。要做到这一点,只需:完成后,关闭终端并打开一个新终端,或者运行:
I like home brew. There's probably a better way to do this, but if you run:
That will print out a nice list of all the relevant paths. Look for the one labeled
EXECUTABLE DIRECTORY
. That's the one you want to add to your path. In my case that's/usr/local/Cellar/ruby/1.9.3-p362/bin/ruby
but I would imagine it would change with newer version of Ruby.I'm using
/bin/bash
as my shell, but the process of adding it to your path should be pretty much the name.I use TextWrangler (via the command line tools) to edit my
.profile
file. To do that, it's just:When your done, either close your terminal and open a new one, or run:
你也可以使用自制软件安装的红宝石。你只是缺少自制软件的自定义宝石集的功能。
首先:
这将打开 Nano 编辑器,
然后将以下内容添加到路径中:
您的 ruby 版本可能会有所不同。
就是这样。它现在应该检测到您的宝石。
哦,顺便说一句,你需要 Ctrl+X > y>按 ENTER 键将文件保存在 nano 中。
You can be fine with ruby installed by homebrew too.. You just lack the functionality of custom gemsets with homebrew.
first do:
this will bring up nano editor,
then add the following to the paths:
your version of ruby will probably vary.
Thats it. It should now detect your gems.
Oh, btw, you need to Ctrl+X > y > ENTER to save a file in nano.
而不是使用 =>
$(cd $(which gem)/..; pwd)
你可以使用这个 => $(brew --prefix ruby)/bin
Instead of using =>
$(cd $(which gem)/..; pwd)
You could use this instead =>
$(brew --prefix ruby)/bin
我认为这有点发展。
只需添加
到您的 .bashrc (或 .bash_profile、.zshrc/.bashrc、.. – 无论您使用什么)。
如果您对 ruby 本身有问题
I think this evolve a bit.
Just add
To your .bashrc (or .bash_profile, .zshrc/.bashrc, .. – whatever you use).
If you have a problem with ruby itself