Search code examples
rubyrbenv

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?


Solution

  • 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
    

    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/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.