Need Help Installing Ruby 2.7.2 on Mac

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.

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

Your Ruby version is 2.6.8, but your Gemfile specified 2.7.5

Below are the instructions which I have followed to solve this issue:

  1. Homebrew install: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. watchman install: brew install watchman
  3. Install Ruby: followed rbenv Official Github Repo link to install the required version of ruby
  4. Install CocoaPods: sudo gem install cocoapods
  5. CocoaPods in fixed location: sudo gem install -n /usr/local/bin ffi cocoapods

After the environment setup, it works perfectly.

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.



Related Topics



Leave a reply



Submit