[英]How to manage ruby version installed without rbenv in rbenv?
I had problems installing ruby with rbenv so I installed it with Homebrew.我在使用 rbenv 安装 ruby 时遇到问题,所以我使用 Homebrew 安装了它。 The problem is that I still want to manage this ruby version with rbenv.
问题是我还是想用rbenv来管理这个ruby版本。 How can I do that?
我怎样才能做到这一点?
Let's say you installed ruby 2.7 (brew does not let you choose patch version): brew install ruby@2.7
.假设您安装了 ruby 2.7(brew 不允许您选择补丁版本):
brew install ruby@2.7
。
We will call this version 2.7-brew
in rbenv but you can call it whatever you like (for example 2.7
).我们将在 rbenv 中调用此版本
2.7-brew
,但您可以随意调用它(例如2.7
)。 Just change all pathes in this answer from 2.7-brew
to 2.7
or to another name.只需将此答案中的所有路径从
2.7-brew
更改为2.7
或其他名称即可。
We want rbenv to manage this ruby version:我们希望 rbenv 管理这个 ruby 版本:
cd ~/.rbenv/versions
mkdir -p 2.7-brew/bin
We need to link our newly installed ruby version: replace <Installed Version>
with the version brew installed (probably 2.7.7 or a greater patch version)我们需要链接我们新安装的 ruby 版本:将
<Installed Version>
替换为安装的 brew 版本(可能是 2.7.7 或更高的补丁版本)
If you don't know the version or the installation directory run:如果您不知道版本或安装目录,请运行:
brew info ruby@2.7
Link this ruby version to the directory we have created:将这个 ruby 版本链接到我们创建的目录:
On Mac computers with apple silicon (M1).在配备 Apple Silicon (M1) 的 Mac 计算机上。
ln -s /opt/homebrew/Cellar/ruby@2.7/<Installed Version>/bin/ruby 2.7-brew/bin/ruby
On Mac computers with amd64 architecture (Intell).在采用 amd64 架构 (Intel) 的 Mac 计算机上。
ln -s /usr/local/Cellar/ruby@2.7/<Installed Version>/bin/ruby 2.7-brew/bin/ruby
Let rbenv know that we added a new ruby version:让 rbenv 知道我们添加了一个新的 ruby 版本:
rbenv rehash
Now, rbenv should be able to use this new ruby version.现在,rbenv 应该可以使用这个新的 ruby 版本了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.