Search code examples
rubymacoshomebrew

How to use the Homebrew's Ruby package instead of the Ruby package that comes with MacOS?


How can I switch from using the version of Ruby that comes with MacOS to the most recent version of Ruby that I downloaded using Homebrew?

My version of MacOS appears to have ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18] already installed with the system at usr/bin/ruby. I tried running brew install ruby to get the most recent version of Ruby however when I run ruby -v the same old version shows up. I figured I probably had to add it to my path so I went to my ~/.bash_profile and added

export PATH="/usr/local/Cellar/ruby/2.6.1/bin/ruby:$PATH"

but still ruby -v shows the old version. I closed the terminal, reopened the terminal, ran source ~/.bash_profile with no luck.


Solution

  • Figured out my mistake.

    export PATH="/usr/local/Cellar/ruby/2.6.1/bin/ruby:$PATH"
    

    Should have been

    export PATH="/usr/local/Cellar/ruby/2.6.1/bin:$PATH"
    

    then just run

    source ~/.bash_profile
    

    and confirm with ruby -v or type -a ruby