How to update Ruby with Homebrew?
brew upgrade ruby
Should pull latest version of the package and install it.
brew update
updates brew itself, not packages (formulas they call it)
Upgrading Global Ruby Version on macOS
As per advice from anothermh, uninstalled rbenv and brew versions of Ruby
Uninstallation
brew uninstall ruby
for removing brew version
Use accepted answer on this SO article for removing rbenv
Install Ruby via RVM
Install RVM as per instructions || as per this
rvm install (ruby version)
rvm --default use (ruby version)
can use rvm list
to see available ruby versions.
How can I update Ruby version 2.0.0 to the latest version in Mac OS X v10.10 (Yosemite)?
Open your terminal and run
curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s stable
When this is complete, you need to restart your terminal for the rvm
command to work.
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
Need help installing Ruby 2.7.2 on Mac
You need to install the latest ruby-build
$ brew unlink ruby-build # remove STABLE version
$ brew install --HEAD ruby-build
$ rbenv install -l | grep '2.7.2'
2.7.2
Only latest stable releases for each Ruby implementation are shown.
Use 'rbenv install --list-all' to show all local versions.
Installing Ruby with Homebrew
in ~/.bash_profile
add the following line
export PATH=/usr/local/Cellar/ruby/1.9.3-p194/bin:$PATH
When you're done, close your terminal and re-open it. You should be fine.
Alternatively, you can execute the follwing in each open shell instead of closing/re-opening:
source ~/.bash_profile
Note:
I highly recommend installing ruby via rvm or rbenv so you can manage multiple ruby versions and use gemsets.
Shopify CLI: Best way to update Ruby for Shopify on OSX 11?
Switching to Homebrew Ruby requires you update the PATH environment variable (zsh shell in OSX11 instead of bash) by running...
$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
I still see a Shopify warning that Ruby 3.1.0 is outside the range supported by the CLI but assume that's a Shopify issue because this page states a requirement of Ruby 2.7+.
Unable to update Ruby on macOS Catalina version 10.15.3
First you need add gpg key.
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Then install rvm via CURL. If you don't have CURL, install it via Homebrew brew install curl
curl -sSL https://get.rvm.io | bash
then rvm list
to get installed version of ruby.
then rvm list known
to get the available version.
then rvm install 2.7.0
to install ruby 2.7.0.
then rvm --default use 2.7.0
to use it.
Install older Ruby versions on a M1 MacBook?
In order to make installing of Ruby versions 2.6.x or 2.7.x successful on M1 MacBook using either rbenv
or asdf
(asdf is used in this example) follow these steps:
Upgrade to the latest version of rbenv
or asdf-ruby
plugin using your prefered installation method. In my case it's asdf-ruby
installed over homebrew:
brew upgrade asdf
asdf plugin update ruby
Reinstall the current versions of openssl
, readline
and ruby-build
in order to have the latest versions and configs:
brew uninstall --ignore-dependencies readline
brew uninstall --ignore-dependencies openssl
brew uninstall --ignore-dependencies ruby-build
rm -rf /opt/homebrew/etc/openssl@1.1
brew install -s readline
brew install -s openssl
brew install -s ruby-build
In your shell config .bashrc
or .zshrc
add the following ENV variables:
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
export LDFLAGS="-L/opt/homebrew/opt/readline/lib:$LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/readline/include:$CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/readline/lib/pkgconfig:$PKG_CONFIG_PATH"
export optflags="-Wno-error=implicit-function-declaration"
export LDFLAGS="-L/opt/homebrew/opt/libffi/lib:$LDFLAGS"
export CPPFLAGS="-I/opt/homebrew/opt/libffi/include:$CPPFLAGS"
export PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH"
This will ensure that the proper libraries and headers are used during the installations and it will ignore the implicit-function-declaration
that is preventing some versions to continue installation. Note that for some other shells like fish
the exporting of these variables will be a bit different.
Now start a new terminal session and you can try installing the older ruby versions:
asdf install ruby 2.7.2
asdf install ruby 2.6.5
Note that really old versions below 2.5 might still have issues. Most of the credits go to this Github issue.
UPDATE
For Ruby 2.2 please change the following variable:
export RUBY_CONFIGURE_OPTS=openssl@1.0
And do a
asdf reshim ruby
Thanks @xjlin0 for this update
How can I switch to ruby 1.9.3 installed using Homebrew?
I suggest you take a look at rvm.
You can then set it as default with rvm use 1.9.3 --default
But if you are happy with your homebrew install.
Then just change the precedence of directories in the PATH
Here is my /etc/paths
# homebrews should always take precedence
/usr/local/bin
# the default stack
/usr/bin
/bin
/usr/sbin
/sbin
This is important generally for homebrew, else the system version of git, ruby, pg_admin,... will all be used instead of the brew version.
if you say which -a ruby
you'll see all the installed rubies, and the precedence in the PATH
eg.
$ which -a ruby
/Users/matthew/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
/Users/matthew/.rvm/bin/ruby
/usr/bin/ruby
UPDATE: I now don't think you should change
/etc/paths
Instead you need to check which of .profile
, .bashrc
, or .bash_login
is being loaded in your shell, and just add /usr/local/bin
to your path.
For me, I only have a .profile
. You can create that file if none of those files already exist in your home directory.
# homebrews should always take precedence
export PATH=/usr/local/bin:$PATH
Related Topics
How to Input Integer Value to an Array, Based Preceeding Row + Column Values
How to List All Versions of a Gem Available at a Remote Site
Extract Links (Urls), with Nokogiri in Ruby, from a Href HTML Tags
How to Check the Gem Version in Ruby at Runtime
Difference Between an It Block and a Specify Block in Rspec
Rails 3 - Restricting Formats for Action in Resource Routes
Rails Fields_For Form Not Showing Up, Nested Form
Error While Installing Ruby-1.8.7 on Fedora 15
Does Objective-C Support Mixin Like Ruby
How to Initialize an Array Inside a Hash in Ruby
Replacing Text in One CSV Column Using Fastercsv
How to List the Currently Available Objects in the Current Scope in Ruby
Where to Place/Access Config File in Gem
How to Change Hash Keys from 'Symbol's to 'String'S
What Is the Use of "#!/Usr/Local/Bin/Ruby -W" at the Start of a Ruby Program