我如何“激活”一个特殊宝石的不同版本?

时间:2021-09-20 07:10:12

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. 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安装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,但到目前为止还不需要在OS级别上对gems进行精确控制)

4 个解决方案

#1


136  

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.

希望它可以帮助。

#2


10  

Use RVM

RVM allows you to manage different versions of Ruby and Gems. You can install a version of ruby using, for example

RVM允许您管理Ruby和Gems的不同版本。例如,您可以使用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.

If you want further namespacing you can set up gemsets; directories which will contain specific gems for a specific project.

如果你想要更多的命名空间,你可以设置gemsets;目录将包含特定项目的特定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. 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.

在您的项目根中自动切换gem、pop .ruby版本和.ruby-gemset文件的过程。弹出Ruby版本和要在其中使用的gemset的名称,RVM wil在cd进入项目目录时选择正确的gemset。

Installing gems into your gemset

Install your gems into your gemset in the usual way using bundler if you are using it:

使用bundler将宝石以通常的方式安装到gemset中:

bundle install

or just using the regular old:

或者只使用普通的旧句:

gem install mygem

The gems will go in the right gemset.

宝石会镶嵌在正确的宝石中。

RVM Alternatives

You might also want to check out rbenv, which does similar job.

您可能还想看看rbenv,它也做类似的工作。

#3


6  

You can use 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.

你就完成了。

#4


3  

EDIT: Just saw your RVM mention in the post. Definitely the way to go.

编辑:刚刚看到你的RVM提到的帖子。绝对是正确的。

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. You can switch back and forth with total ease.

您将希望安装RVM——这是一个令人惊叹的包,可以让您在同一台机器上管理不同的ruby和不同的gem集。你可以轻松地来回切换。

Here's the installation guide: http://rvm.beginrescueend.com/rvm/install/

以下是安装指南:http://rvm.beginrescue eend.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. RVM keeps the gems on each ruby separate, which should help with your question.

一旦一切就绪,您就可以使用rvm列表在命令行中查看所有已安装的rubys,并使用rvm使用ruby-head进行切换。RVM将每个ruby上的宝石分离开来,这将有助于解决您的问题。

#1


136  

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.

希望它可以帮助。

#2


10  

Use RVM

RVM allows you to manage different versions of Ruby and Gems. You can install a version of ruby using, for example

RVM允许您管理Ruby和Gems的不同版本。例如,您可以使用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.

If you want further namespacing you can set up gemsets; directories which will contain specific gems for a specific project.

如果你想要更多的命名空间,你可以设置gemsets;目录将包含特定项目的特定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. 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.

在您的项目根中自动切换gem、pop .ruby版本和.ruby-gemset文件的过程。弹出Ruby版本和要在其中使用的gemset的名称,RVM wil在cd进入项目目录时选择正确的gemset。

Installing gems into your gemset

Install your gems into your gemset in the usual way using bundler if you are using it:

使用bundler将宝石以通常的方式安装到gemset中:

bundle install

or just using the regular old:

或者只使用普通的旧句:

gem install mygem

The gems will go in the right gemset.

宝石会镶嵌在正确的宝石中。

RVM Alternatives

You might also want to check out rbenv, which does similar job.

您可能还想看看rbenv,它也做类似的工作。

#3


6  

You can use 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.

你就完成了。

#4


3  

EDIT: Just saw your RVM mention in the post. Definitely the way to go.

编辑:刚刚看到你的RVM提到的帖子。绝对是正确的。

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. You can switch back and forth with total ease.

您将希望安装RVM——这是一个令人惊叹的包,可以让您在同一台机器上管理不同的ruby和不同的gem集。你可以轻松地来回切换。

Here's the installation guide: http://rvm.beginrescueend.com/rvm/install/

以下是安装指南:http://rvm.beginrescue eend.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. RVM keeps the gems on each ruby separate, which should help with your question.

一旦一切就绪,您就可以使用rvm列表在命令行中查看所有已安装的rubys,并使用rvm使用ruby-head进行切换。RVM将每个ruby上的宝石分离开来,这将有助于解决您的问题。