如何在 Mac OS X Lion 中安装 Ruby 1.9.3?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8139138/
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-06 04:29:51  来源:igfitidea点击:

How can I install Ruby 1.9.3 in Mac OS X Lion?

rubymacososx-lion

提问by Klian

I am trying to install Ruby 1.9.3 but am having problems. I installed RVM, then typed:

我正在尝试安装 Ruby 1.9.3,但遇到了问题。我安装了 RVM,然后输入:

rvm install 1.9.3

The output says:

输出说:

ERROR: Error running ' ./configure....

The log says:

日志说:

configure: WARNING: unrecognized options: --with-libyaml-dir 
checking build system type... x86_64-apple-darwin11.2.0 
checking host system type... x86_64-apple-darwin11.2.0 
checking target system type...x86_64-apple-darwin11.2.0 
checking whether the C compiler works... no
configure: error: in `/Users/myuser/.rvm/src/ruby-1.9.3-p0':
configure: error: C compiler cannot create executables See `config.log' for more details

I downloaded the new XCode from the App Store and installed it.

我从 App Store 下载了新的 XCode 并安装了它。

回答by zzaman

Try using the clang compiler instead of the default:

尝试使用 clang 编译器而不是默认编译器:

rvm install 1.9.3 --with-gcc=clang

回答by Marc M

RVM needs gcc-4.2 to be able to install ruby 1.9.3. Unfortunately Lion does not include anymore gcc-4-2, just the llvm version:

RVM 需要 gcc-4.2 才能安装 ruby​​ 1.9.3。不幸的是,Lion 不再包含 gcc-4-2,仅包含 llvm 版本:

lrwxr-xr-x  1 root  wheel  12 15 feb 17:21 /usr/bin/gcc -> llvm-gcc-4.2

If you have Lion but upgraded from Snow Leopard it is likely that you still have gcc-4.2 If you have a brand new installation of Lion you should download gcc-4.2. I recommned downloading this package.

如果您有 Lion 但从 Snow Leopard 升级,很可能您仍然有 gcc-4.2 如果您有一个全新的 Lion 安装,您应该下载 gcc-4.2。我推荐下载这个包。

https://github.com/kennethreitz/osx-gcc-installer

Check that you have gcc-4.2 installed now:

检查您现在是否安装了 gcc-4.2:

-rwxr-xr-x  1 root  wheel  113024 16 may  2011 /usr/bin/gcc-4.2
lrwxr-xr-x  1 root  wheel      12 15 feb 17:21 /usr/bin/gcc -> llvm-gcc-4.2

Now you can install ruby 1.9.3 as usual:

现在您可以像往常一样安装 ruby​​ 1.9.3:

rvm install 1.9.3
rvm use 1.9.3 --default

回答by jupp0r

If you want to merely install and keep up to date the latest version of Ruby (as opposed to switching between different versions of ruby), you can install ruby via homebrew:

如果您只想安装并保持最新版本的 Ruby(而不是在不同版本的 ruby​​ 之间切换),您可以通过homebrew安装 ruby :

brew install ruby

回答by George

Actually, ruby-1.9.3-p125now works with gcc-llvm. But, the current stable/latest releases of rvmdo not (yet). But that was just rvmbeing cautious and there's now a fix to that workaround in the master branch of rvm.

实际上,ruby-1.9.3-p125现在与gcc-llvm. 但是,当前的稳定/最新版本rvm(还没有)。但这只是rvm谨慎,现在在rvm.

Simply, upgrade rvmto the master branch and install/upgrade ruby:

只需升级rvm到 master 分支并安装/升级ruby

GT-MBP:~ gthiruva$ rvm upgrade ruby-1.9.3-p0 1.9.3
Are you sure you wish to upgrade from ruby-1.9.3-p0 to     ruby-1.9.3-p125? (Y/n): Y
Installing new ruby ruby-1.9.3-p125
Fetching yaml-0.1.4.tar.gz to /Users/gthiruva/.rvm/archives
Extracting yaml-0.1.4.tar.gz to /Users/gthiruva/.rvm/src
Configuring yaml in /Users/gthiruva/.rvm/src/yaml-0.1.4.
Compiling yaml in /Users/gthiruva/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/gthiruva/.rvm/usr
The autodetected CC(/usr/bin/gcc-4.2) is LLVM based, it is not yet fully supported by
ruby and gems, please read `rvm requirements`, and set CC=/path/to/gcc .
Unable to install ruby ruby-1.9.3-p125.         Please install it manually to continue.
GT-MBP:~ gthiruva$ rvm get head
Original installed RVM version:

rvm 1.10.2 by Wayne E. Seguin <[email protected]>, Michal Papis
<[email protected]>`enter code here` [https://rvm.beginrescueend.com/]
...
RVM reloaded!
GT-MBP:~ gthiruva$ rvm reload
RVM reloaded!
GT-MBP:~ gthiruva$ exec bash

rvm 1.10.2 by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> 
[https://rvm.beginrescueend.com/]

GT-MBP:~ gthiruva$ rvm upgrade ruby-1.9.3-p0 1.9.3
Are you sure you wish to upgrade from ruby-1.9.3-p0 to     ruby-1.9.3-p125? (Y/n): Y
Installing new ruby ruby-1.9.3-p125
...
Successfully migrated ruby-1.9.3-p0 to ruby-1.9.3-p125
Upgrade complete!

回答by Sean Vikoren

Try this first:

先试试这个:

rvm get latest

This is what I have working:

这就是我的工作:

  rvm:
    version:      "rvm 1.9.2 by Wayne E. Seguin ([email protected]) [https://rvm.beginrescueend.com/]"

  ruby:
    interpreter:  "ruby"
    version:      "1.9.3p0"
    date:         "2011-10-30"
    platform:     "x86_64-darwin11.2.0"
    patchlevel:   "2011-10-30 revision 33570"
    full_version: "ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]"

回答by sparkle

  1. Open Xcode
  2. Open Xcode preferences
  3. Open Downloadstab
  4. Check Command Line Tools
  1. 打开 Xcode
  2. 打开 Xcode 首选项
  3. 打开下载选项卡
  4. 检查命令行工具

Xcode screenshot

Xcode 截图

回答by ALA

  1. Uninstall/remove all traces of manually installed old ruby versions and extras (sqlite3, libxml2-x.x.x, libxslt-x.x.x) from your /usr/local/ or wherever you installed them.
  2. Download and install JewlryBox http://unfiniti.com/software/mac/jewelryboxwhich is a RVM GUI interface for managing your rubies and gemsets.
  3. In JewlryBox, click "Add Ruby" and choose the version of ruby you want to install (I chose 64 bit, Enabled Shared and didn't check/tick the "Use clang" option).
  1. 从您的 /usr/local/ 或您安装它们的任何地方卸载/删除手动安装的旧 ruby​​ 版本和附加程序(sqlite3、libxml2-xxx、libxslt-xxx)的所有痕迹。
  2. 下载并安装 JewlryBox http://unfiniti.com/software/mac/jewelrybox,它是一个 RVM GUI 界面,用于管理您的红宝石和宝石集。
  3. 在 JewlryBox 中,单击“添加 Ruby”并选择您要安装的 ruby​​ 版本(我选择了 64 位,启用共享并且没有选中/勾选“使用 clang”选项)。

Worked with OS X Lion 10.7.3 and Xcode 4.3 Command Line Tools installed.

与安装的 OS X Lion 10.7.3 和 Xcode 4.3 命令行工具一起使用。

回答by Tejasvi Manmatha

Type following commands

键入以下命令

  • ~ $: source ~/.rvm/scripts/rvm
  • ~ $: type rvm | head -n 1

    rvm is a function

  • ~ $: vi ~/.bash_profile add this line into bash_profile "source ~/.rvm/scripts/rvm"

  • ~ $: rvm install 1.9.3

  • ~ $: rvm use 1.9.3
  • ~ $: 源 ~/.rvm/scripts/rvm
  • ~ $: 输入 rvm | 头-n 1

    rvm 是一个函数

  • ~ $: vi ~/.bash_profile 将此行添加到 bash_profile "source ~/.rvm/scripts/rvm"

  • ~ $: rvm 安装 1.9.3

  • ~ $: rvm 使用 1.9.3

回答by Bent Cardan

Clang wasn't cutting any rubies for me and rvm install rubies failed no matter what with single user rvm. Sudo combined with some permission & $PATH changes to my user made it happen. Here's what I did:

Clang 没有为我切割任何红宝石,无论使用单用户 rvm,rvm install rubies 都失败了。Sudo 结合对我的用户的一些权限和 $PATH 更改使其发生。这是我所做的:

sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )</pre>
sudo rvm pkg install readline
sudo rvm install 1.9.3

Installing rvm from root user makes a shell script at /usr/local/rvm/scripts/rvm Pulled code from this executable and placed it in my .bash_profile so that .bash_profile was saved as:

从 root 用户安装 rvm 在 /usr/local/rvm/scripts/rvm 生成一个 shell 脚本 从这个可执行文件中提取代码并将其放在我的 .bash_profile 中,以便 .bash_profile 保存为:

[ -s "/usr/local/rvm/scripts/rvm" ]] ;
    true ${rvm_path:="/usr/local/rvm"}
    source "/usr/local/rvm/scripts/rvm"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

The user group RVM was created during root user rvm install. Last thing I did was go to my preferences pane in OSX 10.7 and added my user to the new rvm group. Finally I reloaded my terminal and was able to install 1.9.3 through rvm single user.

用户组 RVM 是在 root 用户 rvm 安装期间创建的。我做的最后一件事是转到 OSX 10.7 中的首选项窗格,并将我的用户添加到新的 rvm 组。最后我重新加载了我的终端并且能够通过 rvm 单用户安装 1.9.3。

回答by Karl Katzke

Using rvm, ruby 1.9.3, and attempting to use gcc, I couldn't get Ruby to build cleanly with yaml. While there are a variety of hacks to get yaml compilation to work, none of them seemed to work with rvm. I was troubleshooting late at night and I didn't retain my errors, so I'm working from memory here -- I would appreciate if someone else with a clean environment could test these steps.

使用 rvm、ruby 1.9.3 并尝试使用 gcc,我无法让 Ruby使用 yaml干净地构建。虽然有各种技巧可以让 yaml 编译工作,但它们似乎都不适用于 rvm。我在深夜进行故障排除并且我没有保留我的错误,所以我在这里凭记忆工作——如果环境干净的其他人可以测试这些步骤,我将不胜感激。

Using the --with-gcc=clangsolution produced the mildly infamous error about the yaml parser:

使用该--with-gcc=clang解决方案产生了关于 yaml 解析器的轻微臭名昭著的错误:

It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby. 

Since I need yaml for what I'm going to be doing, and libyaml compiled fine when not being run by rvm, and I even had it installed in /usr/lib after building it by hand, I can't understand why rvm couldn't find and use that version of libyaml, even with the --shared-libsoption.

因为我需要 yaml 来完成我将要做的事情,并且 libyaml 在不被 rvm 运行时编译得很好,我什至在手动构建后将它安装在 /usr/lib 中,我不明白为什么 rvm 不能即使使用该--shared-libs选项,也无法找到并使用该版本的 libyaml 。

Using CC=/usr/bin/gcc rvm install 1.9.3produced errors. In the .rvm/log/ruby-1.9.3-p385/configure.log, I found the following:

使用CC=/usr/bin/gcc rvm install 1.9.3产生的错误。在 .rvm/log/ruby-1.9.3-p385/configure.log 中,我发现了以下内容:

configure: error: C compiler cannot create executables
See `config.log' for more details

That error was also present in .rvm/log/libyaml-0.14/configure.log.

该错误也存在于 .rvm/log/libyaml-0.14/configure.log 中。

The solution for me ended up being to run the rvm command with sudo. Running a compile as root seems to remove Apple's GCC toolchain's disapproval of users doing anything as dirty as compiling software.

我的解决方案最终是使用 sudo 运行 rvm 命令。以 root 身份运行编译似乎消除了 Apple 的 GCC 工具链对用户做任何像编译软件一样肮脏的事情的反对。

So sudo CC=/usr/bin/gcc rvm install 1.9.3 --disable-binarygave me a clean compile of ruby+yaml in the rvm folder. I then needed to sudo chown -R username ~/.rvm && sudo chgrp -R staff ~/.rvmto get things back in my user and running with my permissions.

所以sudo CC=/usr/bin/gcc rvm install 1.9.3 --disable-binary在 rvm 文件夹中给了我一个干净的 ruby​​+yaml 编译。然后我需要将sudo chown -R username ~/.rvm && sudo chgrp -R staff ~/.rvm东西恢复到我的用户中并以我的权限运行。

I do notrecommend compiling things as root, as I see it as a security risk (especially with the vulnerabilities found in the ruby stack and rubygems.org recently) -- but this produced a clean installation of ruby under rvm and might help someone with more talent or time figure out the root cause of the issue with Apple's gcc.

建议以 root 身份编译东西,因为我认为它存在安全风险(尤其是最近在 ruby​​ 堆栈和 ruby​​gems.org 中发现的漏洞)——但这在 rvm 下产生了 ruby​​ 的干净安装,可能会帮助某人更多的人才或时间找出 Apple 的 gcc 问题的根本原因。