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

时间:2022-07-23 09:00:03

Using the command-line gem tool, how can I install a specific version of a gem?

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

6 个解决方案

#1


888  

Use the -v flag:

使用- v标记:

$ gem install fog -v 1.8

#2


148  

Use the --version parameter (shortcut -v):

使用-版本参数(快捷-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 install rails:0.14.4 rubyzip:'< 1'
…
Successfully installed rails-0.14.4
Successfully installed rubyzip-0.9.9

#3


66  

for Ruby 1.9+ use colon..

对于Ruby 1.9+使用冒号。

gem install sinatra:1.4.4 prawn:0.13.0

#4


32  

For installing gem install gemname -v versionnumber

用于安装gem安装gemname -v版本号。

For uninstall gem uninstall gemname -v versionnumber

用于卸载gem卸载gemname -v versionnumber

#5


15  

As others have noted, in general use the -v flag for the gem install command.

正如其他人所指出的,一般使用-v标志用于gem安装命令。

If you're developing a gem locally, after cutting a gem from your gemspec:

如果你在当地开发一颗宝石,在切割宝石的宝石之后:

$ gem install gemname-version.gem

Assuming version 0.8, it would look like this:

假设0。8,它是这样的

$ gem install gemname-0.8.gem

#6


6  

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. Or run /usr/local/rvm/scripts/rvm if your command rvm is not in your global PATH. If rvm installation process failed, see the troubleshooting section.

注意:如果rvm是全局安装的,可以用sudo对其进行前缀。如果命令rvm不在全局路径中,也可以运行/usr/local/rvm/scripts/rvm。如果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:

    如果您想在全球安装一些gem,并且已经安装了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. 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...). 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来处理RVM gems。当您执行sudo时,您正在以root身份运行命令,另一个shell中的另一个用户,因此RVM为您做的所有设置都将被忽略,而命令将在sudo下运行(例如GEM_HOME等)。重申一下,只要你运行的是根系统用户,它就会清除你的环境以及它创建的任何文件,而你的用户无法修改这些文件,这会导致奇怪的事情发生。

#1


888  

Use the -v flag:

使用- v标记:

$ gem install fog -v 1.8

#2


148  

Use the --version parameter (shortcut -v):

使用-版本参数(快捷-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 install rails:0.14.4 rubyzip:'< 1'
…
Successfully installed rails-0.14.4
Successfully installed rubyzip-0.9.9

#3


66  

for Ruby 1.9+ use colon..

对于Ruby 1.9+使用冒号。

gem install sinatra:1.4.4 prawn:0.13.0

#4


32  

For installing gem install gemname -v versionnumber

用于安装gem安装gemname -v版本号。

For uninstall gem uninstall gemname -v versionnumber

用于卸载gem卸载gemname -v versionnumber

#5


15  

As others have noted, in general use the -v flag for the gem install command.

正如其他人所指出的,一般使用-v标志用于gem安装命令。

If you're developing a gem locally, after cutting a gem from your gemspec:

如果你在当地开发一颗宝石,在切割宝石的宝石之后:

$ gem install gemname-version.gem

Assuming version 0.8, it would look like this:

假设0。8,它是这样的

$ gem install gemname-0.8.gem

#6


6  

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. Or run /usr/local/rvm/scripts/rvm if your command rvm is not in your global PATH. If rvm installation process failed, see the troubleshooting section.

注意:如果rvm是全局安装的,可以用sudo对其进行前缀。如果命令rvm不在全局路径中,也可以运行/usr/local/rvm/scripts/rvm。如果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:

    如果您想在全球安装一些gem,并且已经安装了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. 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...). 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来处理RVM gems。当您执行sudo时,您正在以root身份运行命令,另一个shell中的另一个用户,因此RVM为您做的所有设置都将被忽略,而命令将在sudo下运行(例如GEM_HOME等)。重申一下,只要你运行的是根系统用户,它就会清除你的环境以及它创建的任何文件,而你的用户无法修改这些文件,这会导致奇怪的事情发生。