xcode 在 OS X Mavericks 上降级 Ruby 时遇到问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17113823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:30:25  来源:igfitidea点击:

Trouble downgrading Ruby on OS X Mavericks

rubyxcodemacosrvmosx-mavericks

提问by Alextoul

OS X 10.9 comes with ruby 2.0.0p195 but I need to install Ruby 1.8.7. I keep running into errors. I have Xcode5-DP install and I believe Command Line Tools is installed too.

OS X 10.9 带有 ruby​​ 2.0.0p195,但我需要安装 Ruby 1.8.7。我不断遇到错误。我安装了 Xcode5-DP,我相信也安装了命令行工具。

In the terminal:

在终端:

sudo rvm install 1.8.7
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10/x86_64/ruby-1.8.7-p371.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Installing requirements for osx, might require sudo password.
Certificates in '/usr/local/etc/openssl/cert.pem' already are up to date.
Installing Ruby from source to: /Users/alextoul/.rvm/rubies/ruby-1.8.7-p371, this may take a while depending on your cpu(s)...
ruby-1.8.7-p371 - #downloading ruby-1.8.7-p371, this may take a while depending on your connection...
ruby-1.8.7-p371 - #extracted to /Users/alextoul/.rvm/src/ruby-1.8.7-p371 (already extracted)
Patch stdout-rouge-fix was already applied.
Patch no_sslv2 was already applied.
ruby-1.8.7-p371 - #configuring...
Error running 'env CFLAGS=-O3 -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libxml2/include -I/usr/local/opt/libxslt/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl098/include LDFLAGS=-L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libxml2/lib -L/usr/local/opt/libxslt/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl098/lib ./configure --prefix=/Users/alextoul/.rvm/rubies/ruby-1.8.7-p371 --disable-install-doc --without-tcl --without-tk --enable-shared',
please read /Users/alextoul/.rvm/log/ruby-1.8.7-p371/1371228839_configure.log
There has been an error while running configure. Halting the installation.

1371228839_configure.log says:

1371228839_configure.log 说:

./configure
configure: WARNING: unrecognized options: --without-tcl, --without-tk
checking build system type... i686-apple-darwin13.0.0
checking host system type... i686-apple-darwin13.0.0
checking target system type... i686-apple-darwin13.0.0
checking whether the C compiler works... no
configure: error: in `/Users/alextoul/.rvm/src/ruby-1.8.7-p371':
configure: error: C compiler cannot create executables
See `config.log' for more details

Other (useful) info:

其他(有用的)信息:

ruby -v
> ruby 2.0.0p195 (2013-05-14 revision 40734) [universal.x86_64-darwin13]
brew update
> Already up-to-date.
gcc --version
> Configured with: --prefix=/Applications/Xcode5-DP.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode5-DP.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
> Apple LLVM version 5.0 (clang-500.1.58) (based on LLVM 3.3svn)
> Target: x86_64-apple-darwin13.0.0
> Thread model: posix
sudo rvm requirements
> Installing requirements for osx, might require sudo password.
> Certificates in '/usr/local/etc/openssl/cert.pem' already are up to date.

Thanks for your help.

谢谢你的帮助。

回答by RyanWilcox

10.9 is an early beta build of the OS. [Edit: please note the July 2013 date of this answer] If I were running 10.9 I would assume I'll have to reinstall the operating system from scratch at least 2 more times. (At least once during the beta cycle because, well, it's beta, and once when 10.9 comes out in general release, because, well, beta).

10.9 是操作系统的早期测试版。[编辑:请注意此答案的 2013 年 7 月日期] 如果我运行的是 10.9,我会假设我必须从头开始重新安装操作系统至少 2 次。(在测试周期中至少有一次,因为它是测试版,当 10.9 正式发布时,因为,嗯,测试版)。

Given this I suggest four courses of action (pick 1 or many):

鉴于此,我建议采取四个行动方案(选择 1 个或多个):

  • Work with the RVM guys and dig into 10.9's probably-changed compiler environment and get Ruby 1.8.7 compiling. This is trickier because technically this stuff is under NDA.
  • Instead, set up a VM and run Ruby 1.8.7 on the VM. Bonus points for using Vagrantand Chef/Puppet, because you may even need to rebuild the VM. (Just keep the Vagrantfile and Puppet or Chef config files on Github/Dropbox/whatever so you can clone them and regenerate your VM from scratch.)
  • OR simply reboot to 10.8 to get production work done. 10.8 is a production level OS, 10.9 should be treated with caution - it could eat your work. It really shouldn't be used for production purposes (aka: day to day writing Ruby code). If you're writing a 10.9 only app in Cocoa/Objective-C (or updating RubyMotion or something) that might be another thing (but I'd still keep good backups and treat it gently).
  • Work towards updating your code base for Ruby 2.0, as Ruby 1.8.7 is no longer officially supported anyway.
  • 与 RVM 人员一起工作并深入研究 10.9 可能改变的编译器环境并编译 Ruby 1.8.7。这比较棘手,因为从技术上讲,这些东西都在保密协议之下。
  • 相反,设置一个 VM 并在 VM 上运行 Ruby 1.8.7。使用Vagrant和 Chef/Puppet 的加分项,因为您甚至可能需要重建 VM。(只需将 Vagrantfile 和 Puppet 或 Chef 配置文件保存在 Github/Dropbox/任何东西上,这样您就可以克隆它们并从头开始重新生成您的 VM。)
  • 或者只需重新启动到 10.8 即可完成生产工作。10.8 是生产级操作系统,应谨慎对待 10.9 - 它可能会占用您的工作。它真的不应该用于生产目的(又名:日常编写 Ruby 代码)。如果您在 Cocoa/Objective-C(或更新 RubyMotion 或其他东西)中编写仅 10.9 版本的应用程序,那可能是另一回事(但我仍然会保留良好的备份并温和地对待它)。
  • 努力更新 Ruby 2.0 的代码库,因为 Ruby 1.8.7 无论如何都不再受到官方支持。

Edit (Oct 24, 2013):If you're here because you just installed Mavericks (released Oct 22, 2013), want to get Ruby 1.8.7 working a few days after this release, and RVM isn't working for you (because you're impatient and can't wait), here's what you can do (which should work, although I'm not an rbenv user):

编辑(2013 年 10 月 24 日):如果您是因为刚刚安装了 Mavericks(2013 年 10 月 22 日发布而来到这里,希望在此版本发布几天后让 Ruby 1.8.7 运行,并且 RVM 不适合您(因为你不耐烦,等不及了),这是你可以做的(这应该可行,虽然我不是 rbenv 用户):

  1. Use macports to install port install ruby. This is Ruby 1.8.7. This compilation worked for me on my Mavericks machine (although you will need to install Macports from source at this writing andinstall the command line developer tools, even if you have XCode 5 installed. Yes, really).
  2. Now, install rbenv.
  3. Symlink /opt/local/bin/ruby1.8in the ~/.rbenv/versions/folder. Specifically ~/.rbenv/versions/ruby-1.8.7-p374
  4. Read the rbenv documentation, but it should work now! (At least from the documentation. Again, not an rbenvuser, but do play one on TV)
  1. 使用 macports 安装port install ruby. 这是 Ruby 1.8.7。这个编译在我的 Mavericks 机器上对我有用(尽管在撰写本文时您需要从源代码安装 Macports安装命令行开发人员工具,即使您安装了 XCode 5。是的,真的)。
  2. 现在,安装rbenv
  3. 符号链接/opt/local/bin/ruby1.8~/.rbenv/versions/的文件夹。具体来说~/.rbenv/versions/ruby-1.8.7-p374
  4. 阅读 rbenv 文档,但它现在应该可以工作了!(至少来自文档。同样,不是rbenv用户,而是在电视上播放)

I'm sure you can do this with homebrew too, but I know Ruby 1.8.7 installs correctly with the latest Macports, because that's what I use (and it just installed cleanly for me).

我相信你也可以用自制软件来做到这一点,但我知道 Ruby 1.8.7 可以使用最新的 Macports 正确安装,因为这就是我使用的(而且它刚刚为我安装干净)。

回答by konrad

When you see this error message:

当您看到此错误消息时:

configure: error: C compiler cannot create executables:

配置:错误:C 编译器无法创建可执行文件

First of all, make sure you have upgraded your commandline tools:

首先,请确保您已升级命令行工具:

$ xcode-select --install

Now Apple wants you to agree to their license before you can use these tools:

现在,Apple 希望您在使用这些工具之前同意他们的许可:

$ gcc
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.

$ sudo gcc
You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.
[...]

After you have accepted it, the commandline tools will work as expected.

接受后,命令行工具将按预期工作。

回答by David Douglas

If you've installed developer tools on OS X Mavericks Ruby 1.8 is already installed along with 2.0. So all you need to do is switch the 'Current' symbolic link to point to the 1.8 directory.

如果您已在 OS X Mavericks 上安装了开发人员工具,则 Ruby 1.8 已与 2.0 一起安装。因此,您需要做的就是将“当前”符号链接切换为指向 1.8 目录。

#Install Xcode Developer tools
xcode-select --install

#Delete Current symbolic link to Ruby 2.0
sudo rm /System/Library/Frameworks/Ruby.framework/Versions/Current

#Create new Current symbolic link to Ruby 1.8
sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8 /System/Library/Frameworks/Ruby.framework/Versions/Current

#Check Ruby version is 1.8.7
ruby -v

回答by Isaka

Try this (ensure the dev toolchain is reachable):

试试这个(确保可以访问开发工具链):

$ sudo xcode-select -s /Applications/Xcode5-DP.app/Contents/Developer

Then retry.

然后重试。

回答by Vyke

Try switching your compiler

尝试切换编译器

rvm install 1.8.7 --with-gcc=clang