如何在 OSX 上安装 Ruby on Rails 3?

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

How can I install Ruby on Rails 3 on OSX?

ruby-on-railsrubymacosruby-on-rails-3

提问by Oluf Nielsen

I got a White Macbook and I have to go to a conference in 10 hours but I'm having a lot of problems.

我有一台白色 Macbook,我必须在 10 小时后参加一个会议,但我遇到了很多问题。

First, I wanted to have Rails 3, so I used MacPorts to install Ruby 1.8.7. It worked well ;) Then I was thinking I should install Rails 3, but no, no! It says:

首先,我想要 Rails 3,所以我使用 MacPorts 来安装 Ruby 1.8.7。它运行良好 ;) 然后我想我应该安装 Rails 3,但不,不!它说:

$ sudo gem install rails --pre

ERROR: Error installing rails:


            activesupport requires Ruby version >= 1.8.7.
$ sudo gem install rails --pre

ERROR: Error installing rails:


            activesupport requires Ruby version >= 1.8.7.

What should I do? I already have 1.8.7!

我该怎么办?我已经有1.8.7了!

回答by Jarrod

First you need to install RVM, then the latest version of Ruby. Next you'll set that version of Ruby as the default. Finally, you'll install Rails b3.

首先你需要安装 RVM,然后是最新版本的 Ruby。接下来,您将该版本的 Ruby 设置为默认版本。最后,您将安装 Rails b3。

Install RVM (http://rvm.beginrescueend.com/rvm/install/):

安装 RVM ( http://rvm.beginrescueend.com/rvm/install/):

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

Install the latest Ruby (http://rvm.beginrescueend.com/rubies/installing/):

安装最新的 Ruby ( http://rvm.beginrescueend.com/rubies/installing/):

rvm install ruby-head

You can check which versions you now have installed with:

您可以检查您现在安装的版本:

rvm list

Set the latest version of Ruby as default (replace 'ruby-1.9.2-head' with desired version):

将最新版本的 Ruby 设置为默认值(将 'ruby-1.9.2-head' 替换为所需版本):

rvm ruby-1.9.2-head --default

Make sure things are up to day, then install the Rails beta:

确保一切正常,然后安装 Rails 测试版:

gem update --system
gem install rails --pre

You may have to install some gem dependencies before Rails will install.

在安装 Rails 之前,您可能需要安装一些 gem 依赖项。

回答by tommasop

To easily setup Rails 3 on osx machine the only thing you need to do is follow this brilliant (as always) Railscast, here for the transcription

要在 osx 机器上轻松设置 Rails 3,您唯一需要做的就是遵循这个出色的(一如既往)Railscast这里是转录

You can also see comments to check for problems and eventually solutions.

您还可以查看评论以检查问题和最终解决方案。

回答by Konstantin Haase

You should indeed use rvm, but as no one explained to you how to do this without rvm, here you go:

您确实应该使用 rvm,但是没有人向您解释如何在没有 rvm 的情况下执行此操作,因此您可以使用:

sudo gem install tzinfo builder memcache-client rack rack-test rack-mount \
  abstract erubis activesupport mime-types mail text-hyphen text-format   \
  thor i18n rake bundler arel railties rails --prerelease --force

回答by Zachary Wright

You may have two different versions of Ruby installed. Try "gem env" or "sudo gem env" and see which version of Ruby it says you have.

您可能安装了两个不同版本的 Ruby。试试“gem env”或“sudo gem env”,看看它说你有哪个版本的Ruby。

Remove the older one if you have two installed. If all else fails, upgrade to 1.9.x, I believe it is recommended for Rails 3 anyway.

如果您安装了两个,请删除旧的。如果所有其他方法都失败了,请升级到 1.9.x,我相信还是推荐用于 Rails 3。

回答by techiferous

I would strongly recommend using RVM (Ruby Version Manager) to keep your Rails 3 separate from your Rails 2. (One example of Rails 2 conflicting with Rails 3: when you go to the command line to generate a Rails app, will it generate a Rails 2 app or a Rails 3 app? RVM allows you to keep them separate.)

我强烈建议使用 RVM(Ruby 版本管理器)将 Rails 3 与 Rails 2 分开。(Rails 2 与 Rails 3 冲突的一个示例:当您转到命令行生成 Rails 应用程序时,它会生成一个Rails 2 应用程序还是 Rails 3 应用程序?RVM 允许您将它们分开。)

Also, the latest Ruby 1.8.7 will probably not work with Rails 3, so you have to use an earlier patchlevel (248 works for me). Details are here: http://techiferous.com/2010/02/installing-rails-3-beta-with-rvm-and-ruby-1-8-7/

此外,最新的 Ruby 1.8.7 可能不适用于 Rails 3,因此您必须使用较早的补丁级别(248 对我有用)。详细信息在这里:http: //techiferous.com/2010/02/installing-rails-3-beta-with-rvm-and-ruby-1-8-7/

回答by Telemachus

You should use rvmas others have said to manage multiple installations of Ruby and Ruby gems. (If you go that way, take the time to read rvm's documentationcarefully.)

您应该rvm像其他人所说的那样使用来管理 Ruby 和 Ruby gems 的多个安装。(如果您这样做,请花时间仔细阅读rvm的文档。)

However, you should also get comfortable figuring out what version of Ruby your shell is seeing as the default and why. It sounds to me like your $PATHvariable may not be properly updated. The $PATHvariable is what determines whichRuby interpreter or gemcommand is the first seen, if you have more than one installed (as you now do). MacPorts will install new binaries into /opt/local/binby default, and it should also alter your $PATHso that /opt/local/binprecedes /usr/bin(which is where Apple's out of the box Ruby lives).

但是,您还应该了解您的 shell 将哪个 Ruby 版本视为默认版本以及原因。在我看来,您的$PATH变量可能没有正确更新。如果您安装了多个Ruby 解释器或命令(就像您现在所做的那样),该$PATH变量决定了第一个看到的是哪个Ruby 解释器或gem命令。MacPorts的将安装新的二进制文件到/opt/local/bin默认情况下,它也应该改变你的$PATH,这样/opt/local/bin先于/usr/bin(这是苹果的开箱即用Ruby的生活)。

I suspect that when you did sudo gem install, you were using /usr/bin/gem(which is the gem installer for /usr/bin/rubyrather than /opt/local/bin/gem(which would be the installer for MacPort's Ruby).

我怀疑当你这样做时sudo gem install,你正在使用/usr/bin/gem(这是 gem 安装程序,/usr/bin/ruby而不是/opt/local/bin/gem(这将是 MacPort 的 Ruby 的安装程序)。

Check the output of echo $PATH, which rubyand which gemto see what's going on.

检查的输出echo $PATHwhich rubywhich gem看看发生了什么事情。

回答by mipadi

Based on your question and your responses to some of the answers, it sounds like you're not using the MacPorts version of Ruby. You should make sure that /opt/local/binis in the front of your $PATH, before /usr/bin. Also, you should install RubyGems via MacPorts (sudo port install rb-rubygems) and make sure you're using the MacPorts gem. Then install Rails using the MacPorts gem.

根据您的问题和对某些答案的回答,您似乎没有使用 MacPorts 版本的 Ruby。你应该确保它/opt/local/bin在你的前面$PATH,之前/usr/bin。此外,您应该通过 MacPorts ( sudo port install rb-rubygems)安装 RubyGems并确保您使用的是 MacPorts gem。然后使用 MacPorts 安装 Rails gem