User7777
User7777

Reputation: 299

Switch to a different version of ruby using homebrew

I migrated my MacBook using Migration Assistant. I have two rails apps I was working on my previous laptop and now when I try working on those apps on my new laptop one them works properly(Restaurant App) and in the other(Quiz App) when I try to turn on the server I get this

Your Ruby version is 2.2.3, but your Gemfile specified 2.5.1

Both the apps have ruby version 2.5.1. What could be the possible reason the I am able to run the server on one app(Restaurant App) and not the other(Quiz App).

I tried running the command below to switch the ruby version to 2.5.1

brew unlink [email protected] && brew link --force --overwrite [email protected]

but I get an error

No such keg: /usr/local/Cellar/[email protected]

Please help me figure out this problem.

Upvotes: 2

Views: 9266

Answers (2)

gnasher729
gnasher729

Reputation: 52632

I tried to follow the instructions on MacOS 14.0. 2.5.1 doesn't exist anymore. 2.7.0 doesn't build. I installed 2.7.8, with the commands

brew install rbenv rbenv install 2.7.8 rbenv global 2.7.8

This displays a warning

WARNING: ruby-2.7.8 is past its end of life and is now unsupported. It no longer receives bug fixes or critical security updates.

so you might want to try out a later version. (At the moment I'm just following instructions at https://reactnative.dev/docs/environment-setup?guide=native to install react-native and fix all the problems that come up).

Upvotes: 0

Brent Smith
Brent Smith

Reputation: 132

Generally you're better off using a ruby version manager. The two major ones being RVM (https://rvm.io/) and rbenv

I'm personally a big fan of rbenv and its use of shims (I have less trouble when using bundler and switching xcode versions via xcversion personally) https://github.com/rbenv/rbenv

brew install rbenv 
rbenv install 2.5.1
rbenv use 2.5.1

optionally you can use a .ruby-version file in your project root to ensure you don't have an issue again. https://github.com/rbenv/rbenv#choosing-the-ruby-version

# in your project root
echo '2.5.1' > .ruby-version

In this way you can easily select whichever version you'd like to use for your application, just by starting it in the project root.

Upvotes: 8

Related Questions