Search code examples
rubycocoapodshomebrew

trouble upgrading ruby 2.6 on my MacOS 10.15.7


Ultimately I'm trying to install Cocoapods which generates error: Building native extensions ERROR: Error installing cocoapods ERROR: Failed to build gem native extension

..which I assume is because ruby is not latest (stuck at 2.6).

I tried brew install ruby and brew reinstall ruby ...still at v2.6

DOUGs-MacBook-Pro:LOCATION dbell$ 
DOUGs-MacBook-Pro:LOCATION dbell$ 
DOUGs-MacBook-Pro:LOCATION dbell$ 
DOUGs-MacBook-Pro:LOCATION dbell$ 
DOUGs-MacBook-Pro:LOCATION dbell$ brew install ruby
Updating Homebrew...
Warning: ruby 3.0.1 is already installed and up-to-date.
To reinstall 3.0.1, run:
  brew reinstall ruby
DOUGs-MacBook-Pro:LOCATION dbell$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
DOUGs-MacBook-Pro:LOCATION dbell$ 
DOUGs-MacBook-Pro:LOCATION dbell$ brew reinstall ruby
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/manifests/3.0.1
Already downloaded: /Users/dbell/Library/Caches/Homebrew/downloads/6d2a0e9cda0072647ac4fcb119f4f0263b91503dc918ba80d057da0897a3f994--ruby-3.0.1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/blobs/sha256:1af6edba23ff9aa12fcab0fee9246cf46110263bf962e46e800152096b0c7017
Already downloaded: /Users/dbell/Library/Caches/Homebrew/downloads/7d7455d376fe2f0401873034dc82e6daae1f05efe465847b4db1464a73155c8f--ruby--3.0.1.catalina.bottle.tar.gz
==> Reinstalling ruby 
==> Pouring ruby--3.0.1.catalina.bottle.tar.gz
==> Caveats
By default, binaries installed by gem will be placed into:
  /usr/local/lib/ruby/gems/3.0.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH, run:
  echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.profile

For compilers to find ruby you may need to set:
  export LDFLAGS="-L/usr/local/opt/ruby/lib"
  export CPPFLAGS="-I/usr/local/opt/ruby/include"

==> Summary
🍺  /usr/local/Cellar/ruby/3.0.1: 16,358 files, 38.4MB
DOUGs-MacBook-Pro:LOCATION dbell$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
DOUGs-MacBook-Pro:LOCATION dbell$ 

I tried restarting Mac. Still 2.y


Solution

  • The best way to use ruby on mac is to use ruby version manager. I use rbenv. It allows you easly to switch between different ruby versions and doesn't cause conflicts.

    To install it run brew install rbenv ruby-build

    then echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

    and finally source ~/.bash_profile

    now install any ruby for example 3.0.0 by typing rbenv install 3.0.0 and set it globally rbenv global 3.0.0

    edit: This may not work if you're using different shell. Check what shell is your default by running echo $SHELL

    If your default shell is zsh, then instead of your second and third steps run:

    echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc

    echo 'eval "$(rbenv init -)"' >> ~/.zshrc

    source ~/.zshrc