How do I install Ruby gems when using RVM?

前端 未结 3 1991
忘掉有多难
忘掉有多难 2021-02-01 02:14

I set up RVM and used it to install Ruby and a few other libraries. As I was going through various tutorials and set-ups of other technologies like Rails, I began getting confus

3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-01 02:41

    Should I download that tar file they are talking about?

    No. Ruby 1.9+ includes gems. RVM retrofits it for 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.

    Specifically, when working with RVM, you do NOT want to use sudo to install Ruby, or any 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. 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.

    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. Whatever the actual cause, the end result will be weeping and gnashing of teeth.

    RVM doesn't subvert the gem functionality. gem is used to install and manage Ruby gems, and RVM tweaks it to use the sandbox for all its machinations. 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.

提交回复
热议问题