You need to install the correct Ruby version. And it would be best if you use some ruby version manager for that. For example rbenv.
You can try these commands to install and change global Ruby version to 2.7.5
$ brew update
$ brew install ruby-build
$ brew install rbenv
$ rbenv install 2.7.5
$ rbenv global 2.7.5
After that, you need to export some configurations to define rbenv as default global ruby. For zsh users:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
And restart the terminal or run source ~/.zshrc
.
For bash users just replace zshrc
with bashrc
in the above.