简体   繁体   English

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

[英]How can I install Ruby on Rails 3 on OSX?

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. 首先,我想要Rails 3,所以我使用MacPorts来安装Ruby 1.8.7。 It worked well ;) Then I was thinking I should install Rails 3, but no, no! 它工作得很好;)然后我想我应该安装Rails 3,但不,不! It says: 它说:

 $ 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了!

First you need to install RVM, then the latest version of Ruby. 首先,您需要安装RVM,然后安装最新版本的Ruby。 Next you'll set that version of Ruby as the default. 接下来,您将设置该版本的Ruby作为默认值。 Finally, you'll install Rails b3. 最后,您将安装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 beta:

gem update --system
gem install rails --pre

You may have to install some gem dependencies before Rails will install. 在安装Rails之前,您可能必须安装一些gem依赖项。

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. 您还可以查看注释以检查问题并最终解决方案。

You may have two different versions of Ruby installed. 您可能安装了两个不同版本的Ruby。 Try "gem env" or "sudo gem env" and see which version of Ruby it says you have. 尝试“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。

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). 此外,最新的Ruby 1.8.7可能不适用于Rails 3,所以你必须使用更早的补丁级别(248适用于我)。 Details are here: http://techiferous.com/2010/02/installing-rails-3-beta-with-rvm-and-ruby-1-8-7/ 详细信息如下: http//techiferous.com/2010/02/installing-rails-3-beta-with-rvm-and-ruby-1-8-7/

You should use rvm as others have said to manage multiple installations of Ruby and Ruby gems. 您应该使用rvm因为其他人已经说过管理Ruby和Ruby gem的多个安装。 (If you go that way, take the time to read rvm 's documentation carefully.) (如果你这样做,请rvm仔细阅读rvm的文档 。)

However, you should also get comfortable figuring out what version of Ruby your shell is seeing as the default and why. 但是,你也应该很清楚你的shell看到的Ruby的版本是什么,以及为什么。 It sounds to me like your $PATH variable may not be properly updated. 听起来像你的$PATH变量可能没有正确更新。 The $PATH variable is what determines which Ruby interpreter or gem command is the first seen, if you have more than one installed (as you now do). $PATH变量决定了哪个 Ruby解释器或gem命令是第一个看到的,如果你安装了多个(正如你现在所做的那样)。 MacPorts will install new binaries into /opt/local/bin by default, and it should also alter your $PATH so that /opt/local/bin precedes /usr/bin (which is where Apple's out of the box Ruby lives). 默认情况下,MacPorts会在/opt/local/bin安装新的二进制文件,它也应该改变你的$PATH以便/opt/local/bin位于/usr/bin之前(这是Apple的Ruby开箱即用的地方)。

I suspect that when you did sudo gem install , you were using /usr/bin/gem (which is the gem installer for /usr/bin/ruby rather than /opt/local/bin/gem (which would be the installer for MacPort's Ruby). 我怀疑当你做了sudo gem install ,你使用的是/usr/bin/gem (这是/usr/bin/ruby的gem安装程序而不是/opt/local/bin/gem (这将是MacPort的安装程序)红宝石)。

Check the output of echo $PATH , which ruby and which gem to see what's going on. 检查echo $PATH的输出, which rubywhich gem看看发生了什么。

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

Based on your question and your responses to some of the answers, it sounds like you're not using the MacPorts version of Ruby. 根据您的问题和您对某些答案的回答,听起来您没有使用MacPorts版本的Ruby。 You should make sure that /opt/local/bin is in the front of your $PATH , before /usr/bin . /usr/bin之前,您应该确保/opt/local/bin位于$PATH的前面。 Also, you should install RubyGems via MacPorts ( sudo port install rb-rubygems ) and make sure you're using the MacPorts gem . 此外,您应该通过MacPorts安装RubyGems( sudo port install rb-rubygems )并确保您使用的是MacPorts gem Then install Rails using the MacPorts gem . 然后使用MacPorts gem安装Rails。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM