简体   繁体   中英

How to manage ruby version installed without rbenv in rbenv?

I had problems installing ruby with rbenv so I installed it with Homebrew. The problem is that I still want to manage this ruby version with rbenv. 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 .

We will call this version 2.7-brew in rbenv but you can call it whatever you like (for example 2.7 ). Just change all pathes in this answer from 2.7-brew to 2.7 or to another name.

We want rbenv to manage this ruby version:

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)

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:

  • On Mac computers with apple silicon (M1).

    ln -s /opt/homebrew/Cellar/ruby@2.7/<Installed Version>/bin/ruby 2.7-brew/bin/ruby

  • On Mac computers with amd64 architecture (Intell).

    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 rehash

Now, rbenv should be able to use this new ruby version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM