简体   繁体   English

使用自制软件切换到其他版本的红宝石

[英]Switch to a different version of ruby using homebrew

I migrated my MacBook using Migration Assistant. 我使用迁移助手迁移了MacBook。 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 我在以前的笔记本电脑上使用过两个Rails应用程序,现在当我尝试在新笔记本电脑上使用这些应用程序时,其中一个可以正常使用(Restaurant App),而另一个(Quiz App)则可以打开服务器。得到这个

Your Ruby version is 2.2.3, but your Gemfile specified 2.5.1

Both the apps have ruby version 2.5.1. 两个应用程序都具有ruby版本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 我尝试运行以下命令将红宝石版本切换到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. 通常,最好使用ruby版本管理器。 The two major ones being RVM ( https://rvm.io/ ) and rbenv RVM( https://rvm.io/ )和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 我个人是rbenv及其对垫片的使用的忠实拥护者(使用捆绑程序并通过xcversion亲自切换xcode版本时,我的麻烦较少) 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. (可选)您可以在项目根目录中使用.ruby-version文件,以确保不再遇到问题。 https://github.com/rbenv/rbenv#choosing-the-ruby-version 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. 这样,您只需在项目根目录中启动即可轻松选择要用于应用程序的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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