Home > database >  How to manage ruby version installed without rbenv in rbenv?
How to manage ruby version installed without rbenv in rbenv?

Time:01-29

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?

CodePudding user response:

Let's say you installed ruby 2.7 (brew does not let you choose patch version): brew install [email protected].

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 [email protected]

enter image description here

Link this ruby version to the directory we have created:

  • On Mac computers with apple silicon (M1).

    ln -s /opt/homebrew/Cellar/[email protected]/<Installed Version>/bin/ruby 2.7-brew/bin/ruby

  • On Mac computers with amd64 architecture (Intell).

    ln -s /usr/local/Cellar/[email protected]/<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.

  • Related