102

I want to know how to update to the latest stable version of Ruby with Homebrew. I am not interested in using RVM. Thanks.

Ralph David Abernathy
  • 5,230
  • 11
  • 51
  • 78
  • 1
    Are you against RVM or version managers in general? If you don't have old rubies installed, you won't be able to run older Ruby libraries on your computer. Rbenv can be frendlier. I'm not even sure the latest Ruby versions are pushed to system package managers like Homebrew. On ubuntu, the default Ruby version is still 1.9.3 – max pleaner Apr 08 '16 at 02:36

6 Answers6

205

I would use ruby-build with rbenv. The following lines install Ruby 3.2.2 and set it as your default Ruby version:

$ brew update
$ brew install ruby-build
$ brew install rbenv

$ rbenv install 3.2.2
$ rbenv global 3.2.2
spickermann
  • 100,941
  • 9
  • 101
  • 131
  • 8
    Is there no way to automatically update to the latest, stable version of Ruby without "hard coding" the version in there? Something like `rbenv install latest`? – Ralph David Abernathy Apr 07 '16 at 19:40
  • 2
    I prefer to have more control over the version, but you might want to use this example: http://stackoverflow.com/a/30191850/2483313 – spickermann Apr 07 '16 at 19:46
  • 4
    Thanx for the answer. I had to run this as well: echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile – guya Sep 10 '16 at 23:54
  • 1
    Thank you! I then had to run `gem install rails` to get rails and it was all working – svnm Feb 02 '17 at 00:03
  • 11
    The rbenv install felt like it was stuck so if you want to make sure some progress is being made run: `$ rbenv install --verbose 2.4.0` – Vigrant Mar 07 '17 at 20:17
  • 5
    Ok, that worked well, but then how do you update your system to use the homebrew version rather than the default one? – chrismarx Apr 28 '17 at 18:58
  • @chrismarx did you find a solution? – Georges Jan 27 '18 at 12:51
  • 3
    Yeah, see this thread, but basically, you need "eval "$(rbenv init -)" in your ~/.bash_profile - https://github.com/rbenv/rbenv/issues/815 – chrismarx Jan 29 '18 at 15:16
  • if you have a .ruby-version file in your project directory or from wherever you are calling the ruby command, you still need to update that with `rbenv local 2.6.1` otherwise it will override the global setting – bryant Mar 11 '19 at 23:56
  • you do not need this `brew install ruby-build` as it is installed as a dependency when you are installing rbenv. – Stan Dec 14 '19 at 01:35
  • 1
    Also you have to add this: `eval "$(rbenv init -)"` to your .bash_profile or .zshrc, whatever you are using, so that you point to the above version of ruby and not the system one. – Stan Dec 14 '19 at 01:41
104

brew upgrade ruby

Should pull latest version of the package and install it.

brew update updates brew itself, not packages (formulas they call it)

Gustavo Rubio
  • 10,209
  • 8
  • 39
  • 57
15

To upgrade Ruby with rbenv: Per the rbenv README

  • Update first: brew upgrade rbenv ruby-build
  • See list of Ruby versions: versions available: rbenv install -l
  • Install: rbenv install <selected version>
ltrainpr
  • 3,115
  • 3
  • 29
  • 40
7

Adding to the selected answer (as I haven't enough rep to add comment), one way to see the list of available versions (from ref) try:

$ rbenv install -l
ovisirius
  • 87
  • 1
  • 5
2

I followed @spickermann's instructions here, but I was still running into trouble with the Mac System Ruby install being primary (ruby -v did not show my newly installed global ruby). I solved it by executing three more steps:

  1. rbenv init
    
  2. Following the instructions which appeared in the console. For me, using .zshrc:

    # Load rbenv automatically by appending
    # the following to ~/.zshrc:
    eval "$(rbenv init - zsh)"
    

    Yours may be different if you use .bashrc or .bash_profile, instead of .zshrc - in all circumstances, you should be able to change the eval statment to

    eval "$(rbenv init -)"
    

    and have it work equivalently.

  3. Start a new terminal (or re-source your rc file). For me, using .zshrc:

    source ~/.zshrc
    

After following those steps, ruby -v showed the desired version of Ruby and not the system-installed version.


LHM
  • 721
  • 12
  • 31
-4

open terminal

\curl -sSL https://get.rvm.io | bash -s stable

restart terminal then

rvm install ruby-2.4.2

check ruby version it should be 2.4.2

Devesh.452
  • 893
  • 9
  • 10