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?
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 runningmingw-get install msys-make
- Add "C:\MinGW\msys\1.0\bin" and "C:\MinGW\bin" to your path environment variable
\curl -sSL https://get.rvm.io | bash -s stable --ruby
–
Receiptor curl -L --create-dirs -o ~/.config/fish/functions/rvm.fish https://raw.github.com/lunks/fish-nuggets/master/functions/rvm.fish
–
Estebanesteem source /Users/[your username]/.rvm/scripts/rvm
in all open terminals should also allow rvm to work! –
Dichroic gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
–
Bryan RVM is not a function, selecting rubies with 'rvm use ...' will not work
. –
Maryjomaryl sudo
. –
Terylene rvm
. You should only need to execute the indicated source
command, which should work with: source ~/.rvm/scripts/rvm
. –
Guava sudo
in the line: sudo curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | sudo bash -s stable
–
Antiperspirant ruby --version ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]
–
Beveridge gpg: keyserver receive failed: Network is unreachable
–
Beveridge 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
brew link --overwrite ruby
–
Harms overwrite
ruby version, you can just write brew unlink ruby && brew link ruby
–
Thirtyone Error: Could not symlink include/ruby-2.5.0
–
Unsophisticated brew link --overwrite ruby
leads to Warning: Refusing to link macOS-provided software: ruby
–
Maines echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
–
Legate brew link --overwrite ruby --force
. This worked for me. –
Clypeus --force
–
Beveridge 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.
ruby -v
after rbenv global ...
–
Control 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 work –
Crackup rbenv rehash
after rbenv global
worked for me –
Oshiro 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 @Oshiro –
Diglot ruby -v
to show the correct version –
Enabling Open Terminal:
sudo gem update --system
It works!
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 A fast way to upgrade Ruby to v2.4+
brew upgrade ruby
or
sudo gem update --system
/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 ERROR: While executing gem ... (Errno::EPERM) Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem
–
Heydon You can specify the latest version of Ruby by looking at Download Ruby.
Fetch the latest version:
curl -sSL https://get.rvm.io | bash -s stable --ruby
Install it:
rvm install 2.2
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
rbenv
wasn't working –
Control rbenv
did NOT work –
Jojo source ~/.bash_profile
to use rvm
–
Suppose ✅ 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.
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.
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
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
In a terminal: rvm gemset use global
Use
sudo gem update --system
And simply restart the PC.
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).
brew link --overwrite --force ruby
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
© 2022 - 2024 — McMap. All rights reserved.
which rvm
orwhich rbenv
in your command line – Lawsonbrew install ruby
is enough. check here – Tompion