简体   繁体   English

使用RVM时如何安装Ruby gem?

[英]How do I install Ruby gems when using RVM?

I set up RVM and used it to install Ruby and a few other libraries. 我设置了RVM并用它来安装Ruby和其他一些库。 As I was going through various tutorials and set-ups of other technologies like Rails, I began getting confused about what I should do via RVM and what I should just do as the tutorials suggest. 当我正在浏览Rails等其他技术的各种教程和设置时,我开始对通过RVM做什么以及我应该按照教程建议做什么感到困惑。

One example is the RubyGems tutorial here: http://rubygems.org/pages/download 一个例子是RubyGems教程: http//rubygems.org/pages/download

Should I download that tar file they are talking about? 我应该下载他们正在谈论的tar文件吗? Seems unnecessary since that is what I thought RVM was for. 似乎不必要,因为这是我认为RVM的用途。 Do I even need RubyGems? 我甚至需要RubyGems吗? What is that for really? 真的是什么?

Also, how do I actually get Rails? 另外,我如何实际获得Rails? Is there a precise RVM command to actually download and install Rails? 是否有精确的RVM命令来实际下载和安装Rails?

It helps me to think of RVM as a layer of abstraction between you and the ruby ecosystem. 它帮助我将RVM视为您与红宝石生态系统之间的抽象层。

Without RVM: ruby, gems, and ruby related binaries (like rake, spec, gem, etc) are all installed directly into your operating system directories. 没有RVM:ruby,gems和ruby相关的二进制文件(如rake,spec,gem等)都直接安装到您的操作系统目录中。

With RVM: ruby related stuff is intercepted by rvm so that ruby, gems, and ruby related binares are "installed" into ~/.rvm dir in a nice, clean, organized way. 使用RVM:ruby相关的东西被rvm拦截,以便ruby,gems和ruby相关的binares以一种漂亮,干净,有条理的方式“安装”到〜/ .rvm目录中。 RVM sits between ruby, gems, and related binaries and the operating system. RVM位于ruby,gem和相关二进制文件与操作系统之间。 It provides a way to have multiple ruby environments (with different gems and binaries) on the same machine. 它提供了在同一台机器上拥有多个ruby环境(具有不同的gem和二进制文件)的方法。

So, no matter whether you have rvm installed or not, you should be able to run the commands almost exactly(*) as they appear in any tutorials out there on the web. 因此,无论您是否安装了rvm,您都应该能够像在Web上的任何教程中一样运行几乎完全(*)的命令。 In other words, you can sort of "forget" that RVM is installed; 换句话说,您可以“忘记”安装RVM; the ruby ecosystem should work just as if it wasn't installed. 红宝石生态系统应该像没有安装一样工作。

So, yep, you're gonna have to run gem install rails , etc. 所以,是的,你将不得不运行gem install rails等。

Hope that helps clear the confusion. 希望有助于消除混乱。

(*) There are some small differences. (*)有一些小的差异。 For example: you shouldn't run commands as sudo when RVM is installed. 例如:安装RVM时,不应将命令作为sudo运行。

Should I download that tar file they are talking about? 我应该下载他们正在谈论的tar文件吗?

No. Ruby 1.9+ includes gems. 不,Ruby 1.9+包括宝石。 RVM retrofits it for 1.8+. RVM将其改装为1.8+。

In general, be careful with any directions you find on the internet explaining how to install anything, unless you have enough experience to understand completely what they want you to do. 一般情况下,请注意您在互联网上找到的任何说明如何安装任何方向,除非您有足够的经验来完全理解他们希望您做什么。 In particular, any time they want you to install something using sudo or as root. 特别是,只要他们希望您使用sudo或root用户安装。

Specifically, when working with RVM, you do NOT want to use sudo to install Ruby, or any gem . 具体来说,在使用RVM时,您不希望使用sudo来安装Ruby 或任何gem RVM works by setting up a sandbox for your development, and relies on your account's environment, modifying your path so any Ruby requests go to the currently selected RVM-managed Ruby or gems or any commands they install. RVM的工作原理是为您的开发设置一个沙箱,并依赖于您的帐户环境,修改您的路径,以便任何Ruby请求转到当前选定的RVM管理的Ruby或Gems或他们安装的任何命令。 sudo pushes your normal environment to the side, substituting root's temporarily, installs whatever you asked it to do with root's permissions, then reverts to your environment. sudo将你的正常环境推到一边,暂时替换root,安装你要求它做root权限的任何事情,然后恢复到你的环境。

When you go to run the command, or find the gem, as you, it can't be found by RVM's Ruby, because the file was installed outside RVM's sandbox, or, it can't be read or modified, because it's owned by root. 当你去运行命令,或者像你一样找到gem时,RVM的Ruby无法找到它,因为该文件安装在RVM的沙箱之外,或者它无法读取或修改,因为它是由根。 Whatever the actual cause, the end result will be weeping and gnashing of teeth. 无论实际原因是什么,最终的结果都是牙齿的哭泣和咬牙切齿。

RVM doesn't subvert the gem functionality. RVM不会破坏gem功能。 gem is used to install and manage Ruby gems, and RVM tweaks it to use the sandbox for all its machinations. gem用于安装和管理Ruby gems,RVM调整它以使用沙箱进行所有的阴谋。 You get added functionality because of RVM's support of gemsets, but gem works as it always has, only it has "big brother", RVM, controlling its world. 由于RVM对gemsets的支持,你获得了额外的功能,但是gem一如既往地工作,只有它有“大哥”,RVM,控制它的世界。

No need to install rubygems. 无需安装rubygems。 RVM should have already installed rubygems. RVM应该已经安装了rubygems。 RVM is (in my opinion) useful for managing different installations of ruby (say 1.8.7 and 1.9.2) or different gemsets. RVM(在我看来)对于管理不同的ruby安装(比如1.8.7和1.9.2)或不同的gemsets非常有用。 If you just have one version of ruby and don't care about different gemsets, RVM isn't really that much of a change. 如果你只有一个版本的ruby并且不关心不同的gemsets,那么RVM实际上并没有那么大的变化。 If you want to just install rails, just use gem install rails . 如果您只想安装rails,只需使用gem install rails If you have an existing rails 3 app, install bundler first gem install bundler and then bundle install to get rails and other gem dependencies. 如果您有一个现有的rails 3应用程序,请首先gem install bundler ,然后bundle install以获取rails和其他gem依赖项。

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

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