简体   繁体   English

如何“激活”特定宝石的不同版本?

[英]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. 希望能帮助到你。

Use RVM 使用RVM

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

Use specific gems on a per project basis with gemsets. 使用gemsets在每个项目的基础上使用特定的gem。

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

Automation 自动化

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。

Installing gems into your gemset 将gem安装到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. 宝石将进入正确的宝石。

RVM Alternatives RVM替代品

You might also want to check out rbenv, which does similar job. 您可能还想查看rbenv,它可以完成类似的工作。

You can use RVM 您可以使用RVM

Then you can also use Bundler afterwards, which manages gem dependencies fine. 然后你也可以使用Bundler ,它可以很好地管理gem依赖。

In your Gemfile 在你的Gemfile

gem "rails", "2.3.10"

and in your application 并在您的申请中

require 'rubygems'
require 'bundler/setup'

and you're done. 你完成了

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.

相关问题 如何停用特定版本的gem? - How do I deactivate a specific version of gem? 无法激活gem:如何确定哪个gem依赖于此gem? - Can't activate gem: how do I figure out which gem has a dependency on this one? 我如何找出导致特定宝石捆绑在一起的宝石? - How do I figure out which gem(s) caused a particular gem to be bundled? Ruby on Rails 2.3.8:我如何需要特定版本的gem? - Ruby on Rails 2.3.8: How do I require a specifc version of a gem? 我怎么知道gem与某个版本的rails兼容? - How do I know that a gem is compatible with a version of rails? 当我需要不同版本时,如何解决需要最新版本 gem 的捆绑程序问题? - How to fix issue with bundler requiring latest version of gem when I need to require a different version? 如何测试使用不同数据库修改ActiveRecord的gem? - How do I test a gem that modifies ActiveRecord with different DB's? 如何为开发和生产指定不同版本的gem - How do I specify different versions of a gem for development and production 我如何从 jquery-ui-rails gem 版本中找出 JQuery UI 的版本? - How do i figure out the version of JQuery UI from version of jquery-ui-rails gem? 使用databasedotcom ruby​​ gem访问Salesforce时,如何获取特定用户(或帐户)的ActivityHistory - When using databasedotcom ruby gem to access salesforce, how do I get the ActivityHistory for a particular User (or Account)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM