当前位置: 首页 > 工具软件 > Ruby Fog > 使用案例 >

如何安装特定版本的ruby gem?

谢骏奇
2023-12-01

本文翻译自:How to install a specific version of a ruby gem?

使用命令行gem工具,如何安装特定版本的gem?


#1楼

参考:https://stackoom.com/question/19RM1/如何安装特定版本的ruby-gem


#2楼

使用-v标志:

$ gem install fog -v 1.8

#3楼

As others have noted, in general use the -v flag for the gem install command. 正如其他人所指出的,通常在gem install命令中使用-v标志。

If you're developing a gem locally, after cutting a gem from your gemspec: 如果你在gemspec切割宝石后在本地开发宝石:

$ gem install gemname-version.gem

Assuming version 0.8, it would look like this: 假设版本0.8,它看起来像这样:

$ gem install gemname-0.8.gem

#4楼

对于Ruby 1.9+使用冒号..

gem install sinatra:1.4.4 prawn:0.13.0

#5楼

Linux Linux的

To install different version of ruby, check the latest version of package using apt as below: 要安装不同版本的ruby,请使用apt检查最新版本的软件包,如下所示:

$ apt-cache madison ruby
      ruby |    1:1.9.3 | http://ftp.uk.debian.org/debian/ wheezy/main amd64 Packages
      ruby |        4.5 | http://ftp.uk.debian.org/debian/ squeeze/main amd64 Packages

Then install it: 然后安装它:

$ sudo apt-get install ruby=1:1.9.3

To check what's the current version, run: 要检查当前版本是什么,请运行:

$ gem --version # Check for the current user.
$ sudo gem --version # Check globally.

If the version is still old, you may try to switch the version to new by using ruby version manager ( rvm ) by: 如果版本仍旧,您可以尝试使用ruby版本管理器( rvm )将版本切换为新版本:

rvm 1.9.3

Note: You may prefix it by sudo if rvm was installed globally. 注意:如果全局安装rvm则可以使用sudo rvm前缀。 Or run /usr/local/rvm/scripts/rvm if your command rvm is not in your global PATH . 如果您的命令rvm不在您的全局PATH ,请运行/usr/local/rvm/scripts/rvm If rvm installation process failed, see the troubleshooting section. 如果rvm安装过程失败,请参阅故障排除部分。


Troubleshooting: 故障排除:

  • If you still have the old version, you may try to install rvm (ruby version manager) via: 如果您仍有旧版本,可以尝试通过以下方式安装rvm(ruby版本管理器):

    sudo apt-get install curl # Install curl first curl -sSL https://get.rvm.io | bash -s stable --ruby # Install only for the user. #or:# curl -sSL https://get.rvm.io | sudo bash -s stable --ruby # Install globally.

    then if installed locally (only for current user), load rvm via: 然后,如果在本地安装(仅适用于当前用户),请通过以下方式加载rvm:

    source /usr/local/rvm/scripts/rvm; rvm 1.9.3

    if globally (for all users), then: 如果全局(对所有用户),则:

    sudo bash -c "source /usr/local/rvm/scripts/rvm; rvm 1.9.3"
  • if you still having problem with the new ruby version, try to install it by rvm via: 如果您仍然遇到新的ruby版本的问题,请尝试通过rvm安装它:

    source /usr/local/rvm/scripts/rvm && rvm install ruby-1.9.3 # Locally. sudo bash -c "source /usr/local/rvm/scripts/rvm && rvm install ruby-1.9.3" # Globally.
  • if you'd like to install some gems globally and you have rvm already installed, you may try: 如果你想全局安装一些宝石并且你已经安装了rvm,你可以尝试:

    rvmsudo gem install [gemname]

    instead of: 代替:

     gem install [gemname] # or: sudo gem install [gemname]

Note: It's prefered to NOT use sudo to work with RVM gems. 注意:最好不要使用sudo来处理RVM gems。 When you do sudo you are running commands as root, another user in another shell and hence all of the setup that RVM has done for you is ignored while the command runs under sudo (such things as GEM_HOME, etc...). 当您执行sudo时,您正在以root身份运行命令,另一个用户在另一个shell中运行,因此当命令在sudo下运行时(例如GEM_HOME等等),RVM为您完成的所有设置都将被忽略。 So to reiterate, as soon as you 'sudo' you are running as the root system user which will clear out your environment as well as any files it creates are not able to be modified by your user and will result in strange things happening. 所以重申一下,一旦你'sudo'你作为root系统用户运行,它将清除你的环境以及它创建的任何文件都不能被你的用户修改,并将导致奇怪的事情发生。


#6楼

Use the --version parameter (shortcut -v ): 使用--version参数(快捷键-v ):

$ gem install rails -v 0.14.1

You can also use version comparators like >= or ~> 您还可以使用类似>=~>版本比较器

$ gem install rails -v '~> 0.14.0'

Or with newer versions of gem even: 或者使用更新版本的gem甚至:

$ gem install rails:0.14.4 rubyzip:'< 1'
…
Successfully installed rails-0.14.4
Successfully installed rubyzip-0.9.9
 类似资料: