How can I update Ruby version 2.0.0 to the latest version in Mac OS X v10.10 (Yosemite)?
Asked Answered
L

15

513

I need to update my Ruby version from 2.0.0 to the latest version. I can not use some gems because my version is not updated. I had used Homebrew to install Ruby some time ago. How can I update my Ruby version?

Lewendal answered 5/7, 2016 at 1:33 Comment(3)
what happens when you type which rvm or which rbenv in your command lineLawson
@Lewendal Please, take a look here and hereAlerion
looks like brew install ruby is enough. check hereTompion
K
926

Open your terminal and run

curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s stable

For the rvm command to work, you need to run:

source ~/.rvm/scripts/rvm

Now, run rvm list known

This shows the list of versions of the Ruby interpreter.

Now, run rvm install ruby@latest to get the latest Ruby version.

If you type ruby -v in the terminal, you should see ruby X.X.X.

If it still shows you ruby 2.0., run rvm use ruby-X.X.X --default.

Prerequisites for Windows 10:

  • C compiler. You can use http://www.mingw.org/
  • make command available otherwise it will complain that "bash: make: command not found". You can install it by running mingw-get install msys-make
  • Add "C:\MinGW\msys\1.0\bin" and "C:\MinGW\bin" to your path environment variable
Kinchinjunga answered 5/7, 2016 at 1:51 Comment(29)
2.2.0 is not the latest version of Ruby.Thermoluminescence
@Jordan My bad 2.3 is the stable versionKinchinjunga
This works on Mac OS to install RVM: \curl -sSL https://get.rvm.io | bash -s stable --rubyReceiptor
2.4 is the latest stable version: rvm install ruby-2.4.0Orvieto
RVM (rbenv) seems to be the way to go. You can't upgrade the system ruby bundled with MacOS.Angora
I get Searching for binary rubies, this might take some time. No binary rubies available for: osx/10.12/x86_64/ruby-1.9.3-p551. Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies. Checking requirements for osx. Installing requirements for osx. Updating system......... Installing required packages: gcc49.. and stuck here foreverKnavery
If you get requirements installation failed with status 1 run this code then do the above steps then it works: ruby -e "$(curl -fsSL raw.githubusercontent.com/Homebrew/install/master/install)"Knavery
@chpopov, that's not quite true. For a brew only solution to update ruby see my answer belowNunuance
ruby 2.4.1 doesn't compile when upgradingExtinctive
This isn't quite a good solution, because if you want to upgrade ruby version in future, you should do that through rvm. Clearer solution is to install and lead ruby latest version through the brew. Managing 1 tool is easier than 2. Answer below can help on that.Thirtyone
After updating using the 'rvm install ruby-2.4.2' command, when I type 'ruby -v' - I see I am running the current version (I don't think I need to do the other steps of setting the default anymore)Academy
I need to update Ruby because Brew asks me to. However, ruby uses brew, so I get: Homebrew must be run under Ruby 2.3! You're running 2.0.0.... Any solution ?Disarming
to make it work at fish shell, add additional command: curl -L --create-dirs -o ~/.config/fish/functions/rvm.fish https://raw.github.com/lunks/fish-nuggets/master/functions/rvm.fishEstebanesteem
piping curl output straight to execution is a security nightmare waiting to happen.Samsun
@Receiptor You should turn that into an answer. That worked for me.Bungle
You are encouraging people to run a cURL'd script. (piping curl output) Do you think that's smart?Muraida
what is the first slash in front of \curl for ?Heeler
The current stable version is 2.5.1Secondhand
Wanted to add that source /Users/[your username]/.rvm/scripts/rvm in all open terminals should also allow rvm to work!Dichroic
It have to be between "" like this $rvm install "ruby-2.4.6"Holography
As a first step install GPG keys used to verify installation package: gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDBBryan
I got this message: RVM is not a function, selecting rubies with 'rvm use ...' will not work.Maryjomaryl
Why this kind of answer keep poping as "Correct"? 1) Piping some online script directly to bash? Are you insane? 2) There are other far more easier and safe solutions (brew, for instance).Tumbling
I had to add ` --auto-dotfiles` as suggested by the instructions, and run with sudo.Terylene
After the installation you don't need to restart Terminal to start using rvm. You should only need to execute the indicated source command, which should work with: source ~/.rvm/scripts/rvm.Guava
pay attention that this line contains two commands that two of them probably requires super user permission hence, you might want to write this line as follows (mind there are two sudo in the line: sudo curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | sudo bash -s stableAntiperspirant
This doesn't seem to work ruby --version ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21] Beveridge
The gpg fix suggested in the comments also fails with this error: gpg: keyserver receive failed: Network is unreachableBeveridge
Ran into issues with this solution because of root permission needed. Installing via brew then overwriting the link as suggested in @SergioBasurco worked for meJam
N
311

Homebrew-only solution

A better solution

From the comments (kudos to Maksim Luzik), what seems like a more elegant solution:

After installing Ruby through brew, run the following command to update the links to the latest Ruby installation: brew link --overwrite ruby --force

Reopen a terminal to reset zshrc. Check the installlation with ruby --version and gem --version, then run gem install bundler.

Earlier solution

Using brew is enough. It's not necessary to install rvm and for me it just complicated things.

By brew install ruby you're actually installing the latest (currently v2.4.0). However, your path finds 2.0.0 first. To avoid this just change precedence (source). I did this by changing ~/.profile and setting:

export PATH=/usr/local/bin:$PATH

After this, I found that the bundler gem was still using version 2.0.0. Just install it again: gem install bundler

Nunuance answered 16/2, 2017 at 23:22 Comment(13)
Exactly what I was looking for, thanks. If I was a ruby dev then rvm would make sense, but I'm not, so this is perfect.Bet
this works, needed to do "source ~/.bash_profile" after installExtinctive
or after installing ruby through brew, run following command to update the links to the latest ruby installation: brew link --overwrite rubyHarms
instead of overwrite ruby version, you can just write brew unlink ruby && brew link rubyThirtyone
Late to the party but definitely one of the better guests - worked flawlessly.Camera
Error: Could not symlink include/ruby-2.5.0Unsophisticated
@MaksimLuzik 's solution does not work for me in MacOS. brew link --overwrite ruby leads to Warning: Refusing to link macOS-provided software: rubyMaines
Not sure what is is about @rafael-beckel, but just guessing here. How is brew installed? Might be related to sudo rights?Harms
Thanks for the answer regarding i just need one version of ruby.Poteet
this command to add to PATH worked for me (which is also suggested by brew): echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrcLegate
If your mac refuses to link ruby, try brew link --overwrite ruby --force. This worked for me.Clypeus
this worked for me! With --forceBeveridge
Perfect. Perfect. Perfect. My spidey senses told me there was an answer like this out there. Thanks!Lactescent
I
132

I recommend rbenv* https://github.com/rbenv/rbenv

* If this meets your criteria: https://github.com/rbenv/rbenv/wiki/Why-rbenv?:

rbenv does…

  • Provide support for specifying application-specific Ruby versions.
  • Let you change the global Ruby version on a per-user basis.
  • Allow you to override the Ruby version with an environment variable.

In contrast with RVM, rbenv does not…

  • Need to be loaded into your shell. Instead, rbenv's shim approach works by adding a directory to your $PATH.
  • Override shell commands like cd or require prompt hacks. That's dangerous and error-prone.
  • Have a configuration file. There's nothing to configure except which version of Ruby you want to use.
  • Install Ruby. You can build and install Ruby yourself, or use ruby-build to automate the process.
  • Manage gemsets. Bundler is a better way to manage application dependencies. If you have projects that are not yet using Bundler you can install the rbenv-gemset plugin.
  • Require changes to Ruby libraries for compatibility. The simplicity of rbenv means as long as it's in your $PATH, nothing else needs to know about it.

Installation

Install Homebrew http://brew.sh

Then:

brew update
brew install rbenv ruby-build

# Add rbenv to Bash so that it loads every time you open a terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile

rbenv install --list

Output:

Available versions:
 1.8.5-p113
 1.8.5-p114
 […]
 2.3.1
 2.4.0-dev
 jruby-1.5.6
 […]

And:

rbenv install 2.3.1

Set the global version:

rbenv global 2.3.1
ruby -v

Output:

ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]

If you are not showing the updated version then

rbenv rehash

Set the local version of your repository by adding .ruby-version to your repository's root directory:

cd ~/whatevs/projects/new_repo
echo "2.3.1" > .ruby-version

For OS X, visit this link.

Invocate answered 5/7, 2016 at 2:6 Comment(8)
@Lewendal No prob. But before you do, this is from the rbenv readme: "Compatibility note: rbenv is incompatible with RVM. Please make sure to fully uninstall RVM and remove any references to it from your shell initialization files before installing rbenv." — github.com/rbenv/rbenv#installationInvocate
didn't helped. Still getting standard 2.0.0 version for ruby -v after rbenv global ...Control
There's one additional step after brew install rbenv Run rbenv init and add one line to .bash_profile as it states. After that reopen your terminal window, do rbenv install 2.3.1, rbenv global 2.3.1 and rbenv will do its workCrackup
@Crackup I included your additional step in the answer. Thanks!Invocate
Probably late but for future references for people who encountered the same issue as @Control , rbenv rehash after rbenv global worked for meOshiro
After rbenv init, ruby -v outputs the correct version 2.1.2, but bundle runs encounters some error like this paperclip-5.0.0.beta1 requires ruby version >= 2.1.0, which is incompatible with the current version, ruby 2.0.0p648. Finally manage to get it work with a run of rbenv rehash. Thanks @OshiroDiglot
ruby 2.4.1 doesn't compile when upgradingExtinctive
I also had to close and re-open Terminal after the suggestions above to get ruby -v to show the correct versionEnabling
M
75

Open Terminal:

sudo gem update --system 

It works!

Madrid answered 4/11, 2016 at 14:51 Comment(5)
This does indeed seem to work, and is a unmeasurably more straight forward than the other answers. But when installing some gems (listen for example) they complain that the version is lower than required.Entomology
This is gem not rubyKramatorsk
Brew only solution hereNunuance
I was misled by this answer too. It "works" in that no errors are generated when you run it from the console. However, it does not update Ruby. It updates Ruby Gems. Follow one of the other answers to update Ruby (using OS X Sierra).Leveridge
Tried it, but i got the following error: ERROR: Error installing rubygems-update: rubygems-update requires Ruby version >= 2.3.0. ERROR: While executing gem ... (NoMethodError) undefined method `version' for nil:NilClass Maryjomaryl
S
65

A fast way to upgrade Ruby to v2.4+

brew upgrade ruby

or

sudo gem update --system
Swathe answered 9/6, 2017 at 13:30 Comment(6)
This appears to do a ton of stuff, but upgrading ruby isn't one of them. It terminates with: /usr/local/Homebrew/Library/Homebrew/brew.rb:12:in '<main>': Homebrew must be run under Ruby 2.3! You're running 2.0.0. (RuntimeError)Trey
This is the correct and best way to upgrade ruby version using brew.Experience
Doesn't work for me. ERROR: While executing gem ... (Errno::EPERM) Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gemHeydon
@SébastienLoisel can you please give some detail about your OS, command etc.Swathe
@Swathe apparently ruby/gems/etc is in a semibroken state on Mavericks. I've resolved my issues by upgrading to Catalina. I don't remember all the errors I had, but there were multitudes. I can't remember if I was trying to upgrade cocoapods or gems or what, but it was essentially hopeless.Heydon
Mavericks = Mac OS X v10.9 (2013). Catalina = macOS v10.15 (2019). Mac OS X v10.10 (the one in the question) is from 2014. (It may not be relevant, but Catalina introduced Z Shell as the default shell (instead of Bash))Suppliant
G
48

You can specify the latest version of Ruby by looking at Download Ruby.

  1. Fetch the latest version:

    curl -sSL https://get.rvm.io | bash -s stable --ruby
    
  2. Install it:

    rvm install 2.2
    
  3. Use it as default:

    rvm use 2.2 --default
    

Or run the latest command from ruby:

rvm install ruby --latest
rvm use 2.2 --default
Gesticulate answered 13/12, 2016 at 12:40 Comment(3)
Thanks, this worked for me. Solution with rbenv wasn't workingControl
This worked for me too!! The solution with rbenv did NOT workJojo
On Mac I had to do source ~/.bash_profile to use rvmSuppose
I
15

✅ Working 2023 method:

Upgrade using Homebrew:

brew upgrade ruby
echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
brew link --overwrite ruby

Then restart the Terminal (make sure you terminate all instances, quit and open again)

Then ruby -v to check if it linked correctly.


💡Recommended Followup:

It's not required, but you can run the following after upgrading Ruby to update gem files:

gem update --system 3.4.2

⚠️ The above version may be changed when you have upgraded your Ruby installation. Please use the correct version as reported after the installation of Ruby.

Incivility answered 9/10, 2023 at 7:49 Comment(1)
this assumes zshell, which while the default shell on newer macs, many still use bash.Rudich
P
11

Use:

brew install rbenv ruby-build

Add rbenv to Bash so that it loads every time you open a terminal:

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile

source ~/.bash_profile

Install Ruby

rbenv install 2.6.5

rbenv global 2.6.5

ruby -v

Link to the source page.

Photojournalism answered 2/12, 2019 at 5:38 Comment(1)
This "rbenv" may refer to SoAwesomeMan's answer.Suppliant
N
3

In case of the error “Requirements installation failed with status: 1.”, here's what to do:

Install Homebrew (for some reason it might not work automatically) with this command:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then proceed to install rvm again using

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

Quit, reopen Terminal, and then:

rvm install 2.2
rvm use 2.2 --default
Neanderthal answered 3/3, 2017 at 19:51 Comment(0)
J
1

I ended up using the steps below due to React Native 0.70 and macOS v12 (Monterey).

brew install ruby

Edit .zshrc:

open -e ~/.zshrc

Set the $PATH environment variable. Add this at the end of your ~/.zshrc file. On Mac Intel:

if [ -d "/usr/local/opt/ruby/bin" ]; then
  export PATH=/usr/local/opt/ruby/bin:$PATH
  export PATH=`gem environment gemdir`/bin:$PATH
  eval "$(rbenv init -)"
fi

Apple silicon

if [ -d "/opt/homebrew/opt/ruby/bin" ]; then
      export PATH=/opt/homebrew/opt/ruby/bin:$PATH
      export PATH=`gem environment gemdir`/bin:$PATH
      eval "$(rbenv init -)"
    fi

Don't want Homebrew to update your version? Then:

brew pin ruby
Janise answered 27/12, 2022 at 14:48 Comment(0)
G
0

In a terminal: rvm gemset use global

Germangermana answered 13/4, 2017 at 12:39 Comment(1)
While this code snippet may be the solution, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.Berkman
E
0

Use

sudo gem update --system

And simply restart the PC.

Encase answered 13/1, 2023 at 10:31 Comment(0)
S
0

You can use the steps mentioned in How to install Ruby in a macOS for local development.

It worked great for me on macOS v13.3.1 (Ventura) (a) (22E772610a).

Safier answered 23/5, 2023 at 13:8 Comment(2)
What is "22E772610a"? Some kind of version number (building number)? A Mac model number? Something else?Suppliant
@PeterMortensen it is the build number for macOS v13.3.1 (a)Safier
T
-2
brew link --overwrite --force ruby
Tumbleweed answered 18/12, 2022 at 14:20 Comment(1)
Please don't post code-only answers. The main audience, future readers, will be grateful to see explained why this answers the question instead of having to infer it from the code. Also, since this is an old, well answered question, please explain how it complements all other answers.Checkerbloom
G
-3

The simplest way is definitely to enter the following command in the terminal:

sudo gem update --system

You can add the flag --no-document if you do not want to download the documentation. Here is sample output after running the command:

sudo gem update --system
Password:
Updating rubygems-update
Fetching: rubygems-update-2.6.8.gem (100%)
Successfully installed rubygems-update-2.6.8
Parsing documentation for rubygems-update-2.6.8
Installing ri documentation for rubygems-update-2.6.8
Installing darkfish documentation for rubygems-update-2.6.8
Installing RubyGems 2.6.8
RubyGems 2.6.8 installed
Parsing documentation for rubygems-2.6.8
Installing ri documentation for rubygems-2.6.8

------------------------------------------------------------------------------

RubyGems installed the following executables:
    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/gem

Ruby Interactive (ri) documentation was installed. ri is kind of like man
pages for ruby libraries. You may access it like this:
  ri Classname
  ri Classname.class_method
  ri Classname#instance_method
Gerfen answered 18/12, 2016 at 8:4 Comment(1)
Isn't this the same as the answer above? I'm curious why the number of downvotes here versus upvotes there? Is it because of the duplicate answer, or is it because people did not realize soon enough, that the earlier solution was also just for rubygems, not Ruby?Leveridge

© 2022 - 2024 — McMap. All rights reserved.