[英]How do I “activate” a different version of a particular gem?
I want to switch between rails 2.3.10 as the "active" gem for my OS, so that I can invoke it at the command line. 我想在rails 2.3.10之间切换为我的操作系统的“活动”gem,以便我可以在命令行调用它。
Is it possible to do this? 是否有可能做到这一点? I'm not using rvm.
我没有使用rvm。 Maybe it's time to start.
也许是时候开始了。
I tried gem install rails --version=2.3.10
, but that just makes sure that version of the gem is installed, it doesn't put it in /usr/bin/rails
. 我尝试了
gem install rails --version=2.3.10
,但这只是确保安装了gem的版本,它没有把它放在/usr/bin/rails
。
(I do already use bundler for my apps -- but haven't needed any precise control over gems at the OS level until now) (我已经为我的应用程序使用了bundler - 但直到现在才对操作系统级别的宝石进行任何精确控制)
If your problem is to run binaries of a certain version, then: 如果您的问题是运行某个版本的二进制文件,那么:
rails --version # => the latest version
rails _2.3.10_ --version # => Rails 2.3.10
This pattern ( gem-binary _gem-version_
) works for any gem binary. 此模式(
gem-binary _gem-version_
)适用于任何gem二进制文件。
Hope it helps. 希望能帮助到你。
RVM allows you to manage different versions of Ruby and Gems. RVM允许您管理不同版本的Ruby和Gems。 You can install a version of ruby using, for example
例如,您可以使用ruby版本安装
rvm install 1.9.2
You can then use it using: 然后您可以使用它:
rvm use 1.9.2
If you want further namespacing you can set up gemsets; 如果你想要进一步的命名空间,你可以设置gemsets; directories which will contain specific gems for a specific project.
将包含特定项目的特定gem的目录。
rvm gemset create myproject
then you can use them like so: 然后你可以这样使用它们:
rvm use 1.9.2@myproject
To automate the process of switching gems, pop .ruby-version and .ruby-gemset files in your project root. 要自动切换gems的过程,请在项目根目录中弹出.ruby-version和.ruby-gemset文件。 Pop the version of Ruby and name of the gemset you want to use inside them and RVM wil select the correct gemset when you cd into your project directory.
弹出Ruby的版本和要在其中使用的gemset的名称,RVM将在您进入项目目录时选择正确的gemset。
Install your gems into your gemset in the usual way using bundler if you are using it: 如果您正在使用它,请使用bundler以常规方式将gem安装到gemset中:
bundle install
or just using the regular old: 或者只是使用常规旧:
gem install mygem
The gems will go in the right gemset. 宝石将进入正确的宝石。
You might also want to check out rbenv, which does similar job. 您可能还想查看rbenv,它可以完成类似的工作。
EDIT: Just saw your RVM mention in the post. 编辑:刚刚在帖子中看到了你的RVM提及。 Definitely the way to go.
绝对是要走的路。
You're going to want to install RVM -- it's an amazing package that will let you manage different Rubys and different sets of gems on the same machine. 您将要安装RVM - 这是一个惊人的包,可以让您在同一台机器上管理不同的Rubys和不同的宝石。 You can switch back and forth with total ease.
您可以轻松来回切换。
Here's the installation guide: http://rvm.beginrescueend.com/rvm/install/ 这是安装指南: http : //rvm.beginrescueend.com/rvm/install/
Once you got everything get up, you can see all of your installed rubys at the command line with with rvm list
, and switch with rvm use ruby-head
, for example. 一旦你搞定了所有内容,你可以在命令行中看到所有已安装的rubys,并使用
rvm list
,然后使用rvm use ruby-head
切换rvm use ruby-head
。 RVM keeps the gems on each ruby separate, which should help with your question. RVM将每个ruby上的gem保持独立,这应该有助于你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.