0

My computer came with Ruby 1.8.7 installed by default. I installed Homebrew and then used it to install the latest version of ruby. When I run the following commands, I get differing responses:

brew upgrade ruby
Warning: ruby 2.6.5 is already installed and up-to-date

ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

Not only do the versions on these two disagree, but neither of them are the most recent version of Ruby (2.7). How do I make sure what version of Ruby I have installed, and use the latest version?

Note: this question isn't a duplicate of this question because brew install ruby@2.7.0 and other similar commands have no effect, and also because the main issue is with version disagreement.

fin444
  • 725
  • 2
  • 14
  • 27
  • 1
    Install RVM with `\curl -sSL https://get.rvm.io | bash -s stable`; restart your shell; install Ruby with `rvm install 2.6.0` (for example). [Don't](https://robots.thoughtbot.com/psa-do-not-use-system-ruby) [use](https://chrisherring.co/posts/why-you-shouldn-t-use-the-system-ruby) [system Ruby](http://billpatrianakos.me/blog/2014/05/15/never-use-system-ruby-ever/). – anothermh Jan 02 '20 at 02:33
  • Homebrew is a community-driven Open Source Project. You are a part of that community. If there is no formula for Ruby 2.7 yet, then the reason is that the community (and that includes *you*) has not done the work yet to update the formula. That is understandable since in many parts of the world, it is currently holiday time. – Jörg W Mittag Jan 02 '20 at 10:52

2 Answers2

2

My system has:

± /usr/bin/ruby --version

ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]

± ruby --version

ruby 2.4.7p357 (2019-08-28 revision 67796) [x86_64-darwin19]

The reason for this is the order of the directories in the PATH variable. It's read left-to-right, so if you'd like to make sure homebrew's ruby takes precedence, put /usr/local/bin as the left-most member of your PATH variable. If you need further assistance, leave a comment.

hd1
  • 33,938
  • 5
  • 80
  • 91
  • I followed [these instructions](https://stackoverflow.com/a/10343891/9070242) to find my path file, but the first line already reads `/usr/local/bin`. – fin444 Jan 02 '20 at 19:39
  • `if [ -x /usr/libexec/path_helper ]; then eval /usr/libexec/path_helper -s fi if ["${BASH-no}" != "no" ]; then [ -r /etc/bashrc ] && . /etc/bashrc fi` – fin444 Jan 03 '20 at 00:18
  • Kindly execute `/usr/libexec/path_helper -s`? – hd1 Jan 03 '20 at 02:20
  • `PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Users/{my user}/Desktop/{deleted folder}/tools"; export PATH;` I deleted the folder that has its name replaced with `{deleted folder}` a long time ago. – fin444 Jan 03 '20 at 20:37
  • 1
    I'll echo the suggestion of @anothermh, just install rvm and be happier. – hd1 Jan 03 '20 at 21:12
1

As recommended by @anothermh and @hd1, I used RVM instead of Homebrew:

Install RVM with \curl -sSL https://get.rvm.io | bash -s stable; restart your shell; install Ruby with rvm install 2.6.0 (for example).

fin444
  • 725
  • 2
  • 14
  • 27