简体   繁体   中英

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 ruby@2.2.3 && brew link --force --overwrite ruby@2.5.1

but I get an error

No such keg: /usr/local/Cellar/ruby@2.2.3

Please help me figure out this problem.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM