简体   繁体   English

在Mac上安装Ruby&Rails

[英]Ruby & Rails installation on a Mac

I used railstutorial.org to install the latest version of ruby and the latest version of rails on my machine. 我使用railstutorial.org在计算机上安装了最新版本的ruby和最新版本的rails。

at the end of the installation I checked 在安装结束时,我检查了

ruby -v ==> 1.9.2 (great)
rails -v ==> 3.0.1 (great)

this morning I opened up terminal 今天早上我开了航站楼

ruby -v
ruby 1.8.6 (2009-06-08 patchlevel 369) [universal-darwin9.0]
rails -v
Rails 1.2.6

what happened? 发生了什么?

My advice for people who are installing ruby is to use RVM . 对于安装ruby的人,我的建议是使用RVM It makes managing your ruby versions and gem versions really simple and you can install multiple ruby versions side by side. 它使管理红宝石版本和gem版本变得非常简单,并且您可以并排安装多个红宝石版本。

With many unix variants, you are likely to have multiple versions of Ruby--particularly if you installed Ruby 1.9 and the system already had 1.8 installed. 对于许多unix变体,您可能具有多个版本的Ruby,尤其是如果您安装了Ruby 1.9并且系统已经安装了1.8。 Essentially, the 1.8 version of Ruby has a higher precedence in your PATH than the 1.9 version. 本质上,Ruby的1.8版本在PATH中的优先级高于1.9版本。 The Ruby Gems command keeps the libraries separate between 1.8 and 1.9 so that the platform will be reasonably stable. Ruby Gems命令将库分开在1.8和1.9之间,以便该平台相当稳定。

To correct the problem, you have to find where ruby 1.9 is installed. 要解决此问题,您必须找到ruby 1.9的安装位置。 Once you do that, you'll need to override your PATH variable. 完成此操作后,您将需要覆盖PATH变量。 Assuming 1.9 is installed in the path: /opt/ruby-1.9.2 , you will need to set your PATH like this: 假设1.9安装在/opt/ruby-1.9.2路径中,则需要这样设置PATH:

PATH=/opt/ruby-1.9.2/bin:$PATH
export PATH

To make the path respect what you want every time, add that to your ~/.profile file (create it if necessary). 为了使路径始终符合您的要求,请将其添加到~/.profile文件中(如有必要,请创建它)。 Once the path has been set, it sould be able to find the correct version of Rails again. 设置好路径后,便可以再次找到正确的Rails版本。

You can use Cinderalla to the whole ruby/rvm/mysql/redis/git/... stack set up properly. 您可以使用Cinderalla对ruby / rvm / mysql / redis / git / ...整个堆栈进行正确设置。 Cinderella installs everything in ~/Developer and fixes up your PATH as well. 灰姑娘将所有内容安装在~/Developer并修复了PATH I had some issues with a corrupt git mirror last time I used Cinderalla though so YMMV. 上次我使用Cinderalla时,我的git镜像损坏了一些问题,尽管如此,YMMV还是这样。

I cannot say for certain because I cannot debug you OSX machine from here, however, I had a very similar occurrence. 我不能肯定地说,因为我不能从这里调试OSX机器,但是,我发生了非常相似的事情。 The problem was caused because I had installed ruby and then rails on my machine using sudo or from the root account. 造成此问题的原因是,我先使用sudo或root帐户在计算机上安装了ruby,然后安装了rails。 Then when I discovered rvm I installed everything in my user account. 然后,当我发现rvm时,我便在用户帐户中安装了所有内容。 When I logged off and back in I appeared to lose everything. 当我注销并重新登录时,我似乎失去了一切。 I was pulling out my hair. 我正在拔头发。 I was pissed that I was going to have to reinstall everything again... when I found the magic. 当我发现魔力时,我很生气,不得不重新安装所有东西。

from the command line execute the command: 从命令行执行命令:

rvm list

you'll see that your new version of ruby is there. 您会看到新版本的ruby在那里。 you'll also notice the tokens that indicate that it is just a normal version. 您还会注意到指示这只是普通版本的标记。 It is not current or default. 它不是当前的或默认的。 (see it yet) (看到它了)

Now if you run the command: 现在,如果您运行命令:

rvm use 1.9.2 --default

then every time you login/off and restart your machine your user account will default to that version of ruby and all of the gems that you installed against that version. 然后,每次您登录/注销并重新启动计算机时,您的用户帐户将默认为该版本的ruby以及针对该版本安装的所有gem。

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

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