在 Mac 上使用不同的应用分别设置 ruby 版本

Setting ruby version separately with different app on Mac

我刚刚开始从事 ruby 项目,我注意到我必须指定 ruby 版本才能在全球范围内使用。例如,我正在使用 chruby 更改要使用的 ruby 版本,我可以直接在这个名为 .zshrc.

的文件中设置它

但是如果我有多个 ruby 版本不同的应用程序,那么我该如何处理呢?如果每次我想 运行 另一个应用程序时,我都不断更改要在 .zshrc 文件中使用的版本,这是没有意义的。

因为这是一个共享项目,所以我不能只更改应用程序中使用的版本。谢谢。

chruby 中,此功能称为“Auto-switching”。

If you want chruby to auto-switch the current version of Ruby when you cd between your different projects, simply load auto.sh in ~/.bashrc or ~/.zshrc:

..

chruby will check the current and parent directories for a .ruby-version file.

https://github.com/postmodern/chruby#auto-switching