practicemakesperfect
practicemakesperfect

Reputation: 414

Ruby doesn't work on Mac after installed with Brew

I'm on Mac with OS X El Capitan. I installed ruby with brew install ruby in the terminal, but when I type ruby -v or ruby --version, nothing came up. If I run a simple ruby file with output, nothing showed either. I tried to use binding.pry to stop the script, but it didn't stop and nothing showed in the terminal. I thought the install wasn't successful but when I run brew install ruby again, I says "ruby-2.3.0 already installed". I wonder what the problem is.

Upvotes: 0

Views: 1193

Answers (2)

Khanh Pham
Khanh Pham

Reputation: 2973

in ~/.bash_profile add the following line

export PATH="$(brew --prefix)/opt/ruby/bin:$PATH"

When you're done, close your terminal and re-open it. You should be fine.

Or if you don't want to re-open your terminal, you can do this:

source ~/.bash_profile

I suggest that you should install ruby via rvm or rbenv.

Upvotes: 1

tunagami
tunagami

Reputation: 51

I would remove ruby from homebrew and suggest installing either rbenv (https://github.com/rbenv/rbenv) or rvm (https://rvm.io/) with brew (rbenv is my preferred).

This way you can have multiple versions of ruby on your system at any time and switch between which version you want for different projects. It is quite nice.

Upvotes: 0

Related Questions