如何在Mac Ventura上安装旧版本的Ruby

huangapple go评论86阅读模式
英文:

How to install an older version of ruby on Mac Ventura

问题

我正在尝试打开一个旧的Rails 5应用程序。我已经有好几年没有编写代码了,很难记住...
而且我有一台新电脑(macOS Ventura),我不得不重新安装Homebrew、Xcode、Ruby等...
这个应用程序的Ruby版本是ruby '2.4.4'

我正在逐渐修复问题,但我卡在这里:

当我尝试安装旧版本的Ruby时,我遇到了这个问题:

rbenv install 2.4.4
要跟踪进度,请使用'tail -f /var/folders/bh/wbvn20493_s066frg6c2wwx00000gn/T/ruby-build.20230615201145.8783.log'或传递--verbose
正在下载 ruby-2.4.4.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.4.tar.bz2
正在安装 ruby-2.4.4...

警告:ruby-2.4.4已经过时,不再受支持。
它不再接收错误修复或关键安全更新。


构建失败(在macOS 13.4上使用ruby-build 20230615)

在/var/folders/bh/wbvn20493_s066frg6c2wwx00000gn/T/ruby-build.20230615201145.8783.nJ19PV中检查或清理工作树
结果记录在/var/folders/bh/wbvn20493_s066frg6c2wwx00000gn/T/ruby-build.20230615201145.8783.log中

最后10行日志:
../.././include/ruby/ruby.h:1753:56: 注意:从宏'rb_intern'展开
        __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                                                       ^
closure.c:263:14: 错误:调用未声明的函数'ffi_prep_closure';ISO C99及以后的版本不支持隐式函数声明[-Wimplicit-function-declaration]
    result = ffi_prep_closure(pcl, cif, callback, (void *)self);
             ^
生成了6个警告和1个错误。
make[2]: *** [closure.o] 错误1
make[1]: *** [ext/fiddle/all] 错误2
make: *** [build-ext] 错误2
英文:

I am trying to open an old Rails 5 app. I haven't code for years and it's hard to remember...
Also I have a new computer (mac 0S Ventura) and I had to reinstall hombrew, xcode, ruby etc...
The ruby version of this app was ruby '2.4.4'

I am fixing little by little the problems but I am stuck there:

When I try to install an older version of ruby i have this :

rbenv install 2.4.4                                                                                                                                                    [(3.2.2)]
To follow progress, use 'tail -f /var/folders/bh/wbvn20493_s066frg6c2wwx00000gn/T/ruby-build.20230615201145.8783.log' or pass --verbose
Downloading ruby-2.4.4.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.4.tar.bz2
Installing ruby-2.4.4...

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


BUILD FAILED (macOS 13.4 using ruby-build 20230615)

Inspect or clean up the working tree at /var/folders/bh/wbvn20493_s066frg6c2wwx00000gn/T/ruby-build.20230615201145.8783.nJ19PV
Results logged to /var/folders/bh/wbvn20493_s066frg6c2wwx00000gn/T/ruby-build.20230615201145.8783.log

Last 10 log lines:
../.././include/ruby/ruby.h:1753:56: note: expanded from macro 'rb_intern'
        __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                                                       ^
closure.c:263:14: error: call to undeclared function 'ffi_prep_closure'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    result = ffi_prep_closure(pcl, cif, callback, (void *)self);
             ^
6 warnings and 1 error generated.
make[2]: *** [closure.o] Error 1
make[1]: *** [ext/fiddle/all] Error 2
make: *** [build-ext] Error 2

答案1

得分: 2

正如其他人提到的,Ruby 2.4.4非常古老,最好尝试安装一个更新的版本,然后更新你的Rails应用程序以使用该更新版本。如果可行的话,我写了一个详细的逐步指南,介绍了如何以及为什么升级项目中的Ruby版本

然而,理解你可能想先让你的Rails应用程序在2.4.4上运行,然后逐步更新到更新的Ruby和Rails版本。在这种情况下,在macOS Ventura上安装2.4.4是完全可能的,比2.3.8和更早版本要容易得多。我在我的在macOS上安装较旧Ruby版本的指南中有解释。

另一件需要记住的事情是有几个Ruby版本管理器,它们并不都工作方式相同。它们都有不同的优缺点。我看到你尝试使用rbenv安装Ruby 2.4.4。我个人推荐ruby-install,因为它是最可靠的。我刚刚用它成功地在我的M1 Mac上通过Rosetta安装了Ruby 2.4.10,方法是运行ruby-install 2.4.10

正如我在关于升级Ruby版本的文章中所解释的,你总是要使用给定Ruby版本的最新修订版本。修订版本是第三位数字。在你的情况下,由于你正在使用Ruby 2.4,你希望使用2.4.x系列中的最新版本,即2.4.10。

以下是如何安装它的步骤:

如果你有一台Intel Mac,这是高层次的步骤:

  1. 完全卸载rbenv和你可能安装过的其他版本管理器。

  2. 退出并重新启动终端。

  3. 使用brew install ruby-install chruby来安装ruby-installchruby

  4. 使用ruby-install 2.4.10来安装2.4.10。

  5. 配置你的shell启动文件以使用chruby。

  6. 按照我的升级Ruby版本的指南中的步骤,将你的Rails应用程序从2.4.4更新到2.4.10。

要获取更详细的逐步指南,请阅读我的在macOS上安装较旧Ruby版本的指南

如果你有一台带有M1或M2芯片的Apple Silicon Mac,你需要使用Rosetta运行终端,并重新安装所有开发工具,包括Homebrew。要使用Rosetta运行终端,请按照以下步骤进行:

  1. 如果终端正在运行,请退出。

  2. 转到Finder。

  3. 通过按Shift-Command-U(或选择“前往”菜单,然后选择“实用工具”)转到“实用工具”文件夹。

  4. 单击一次终端应用程序以选择它,但不要启动它。

  5. 按下⌘-i键盘快捷键以打开“信息”窗口(或从菜单栏:选择“文件”,然后选择“获取信息”)。

  6. 勾选“使用Rosetta”复选框。

  7. 关闭“终端信息”窗口。

  8. 启动终端。

  9. 运行arch命令。它应该显示为i386

现在你可以安装Homebrew了,它会检测到你正在使用Rosetta,并将一切安装到/usr/local而不是/opt/homebrew

然后按照Intel部分的相同步骤进行操作。

或者,你可以像上面的评论中提到的那样使用Docker。我个人不使用Docker,所以我没有详细的教程,但我知道有很多教程可以告诉你如何为Rails应用程序设置Docker。

英文:

As others have mentioned, Ruby 2.4.4 is very old, and it's best to try to install a newer version, then update your Rails app to use that newer version. If that's feasible, I wrote a detailed step-by-step guide that goes over How and Why to Upgrade the Ruby Version in Your Project.

However, it's understandable that you might want to get your Rails app running with 2.4.4 first, and then update it little by little to newer versions of Ruby and Rails. In that case, it's definitely possible to install 2.4.4 on macOS Ventura, and it's much easier than versions 2.3.8 and older. I explain this in my guide to installing older Ruby versions on macOS.

Another thing to keep in mind is that there are several Ruby version managers, and they don't all work the same. They all have different pros and cons. I see that you tried to install Ruby 2.4.4 with rbenv. I personally recommend ruby-install because it's the most reliable. I just used it to install Ruby 2.4.10 successfully on my M1 Mac with Rosetta by running ruby-install 2.4.10.

As I explain in my article about upgrading your Ruby version, you always want to use the latest patch version for any given Ruby version. The patch version is the 3rd digit. In your case, since you're using Ruby 2.4, you want to use the latest possible in the 2.4.x series, which is 2.4.10.

Here's how to install it:

If you have an Intel Mac, here are the high level steps:

  1. Completely uninstall rbenv and any other version managers you might have installed

  2. Quit and restart Terminal

  3. Install ruby-install and chruby with brew install ruby-install chruby.

  4. Install 2.4.10 with ruby-install 2.4.10.

  5. Configure your shell startup file to use chruby

  6. Follow my guide for upgrading your Ruby version to update your Rails app from 2.4.4 to 2.4.10

For a more detailed step-by-step guide, read my guide to installing older Ruby versions on macOS.

If you have an Apple Silicon Mac with the M1 or M2 chip, you'll need to run Terminal with Rosetta and reinstall all dev tools over again, including Homebrew. To run Terminal with Rosetta, follow these steps:

  1. Quit Terminal if it’s running

  2. Go to the Finder

  3. Go to the Utilities folder by pressing shift-command-U (or select “Go” from the menu bar, then select Utilities)

  4. Click once on the Terminal app to select it, but don’t launch it.

  5. Press the ⌘-i keyboard shortcut to open the Info window (or from the menu bar: “File”, then “Get Info”).

  6. Check the checkbox that says “Open using Rosetta”

  7. Close the Terminal Info window

  8. Launch Terminal

  9. Run arch. It should say i386

You can now install Homebrew, which will detect that you're using Rosetta and will install everything in /usr/local instead of /opt/homebrew.

Then follow the same steps as in the Intel section.

Alternatively, you can use Docker as mentioned in the comments above. I don't use Docker personally, so I don't have a detailed tutorial, but I know there are plenty out there that show how to set up Docker for a Rails app.

huangapple
  • 本文由 发表于 2023年6月16日 02:35:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76484585.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定