如何安装特定版本的 ruby gem?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17026441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install a specific version of a ruby gem?
提问by mjs
Using the command-line gemtool, how can I install a specific version of a gem?
使用命令行gem工具,如何安装特定版本的 gem?
回答by mjs
Use the -vflag:
使用-v标志:
$ gem install fog -v 1.8
回答by schmijos
Use the --versionparameter (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 gemeven:
或者甚至使用更新版本的gem:
$ gem install rails:0.14.4 rubyzip:'< 1'
…
Successfully installed rails-0.14.4
Successfully installed rubyzip-0.9.9
回答by Emjey
For installing
gem install gemname -v versionnumber
用于安装
gem install gemname -v versionnumber
For uninstall
gem uninstall gemname -v versionnumber
用于卸载
gem uninstall gemname -v versionnumber
回答by Kokizzu
for Ruby 1.9+ use colon..
对于 Ruby 1.9+ 使用冒号..
gem install sinatra:1.4.4 prawn:0.13.0
回答by thelostspore
As others have noted, in general use the -vflag for the gem installcommand.
正如其他人所指出的,通常使用命令的-v标志gem install。
If you're developing a gem locally, after cutting a gem from your gemspec:
如果您在本地开发 gem,在从您的 gemspec 切割 gem 之后:
$ gem install gemname-version.gem
Assuming version 0.8, it would look like this:
假设版本 0.8,它看起来像这样:
$ gem install gemname-0.8.gem
回答by kenorb
Linux
Linux
To install different version of ruby, check the latest version of package using aptas 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 sudoif rvmwas installed globally. Or run /usr/local/rvm/scripts/rvmif your command rvmis not in your global PATH. If rvm installation process failed, see the troubleshooting section.
注意:您可以使用sudoifrvm全局安装作为前缀。或者,/usr/local/rvm/scripts/rvm如果您的命令rvm不在您的 global 中,则运行PATH。如果 rvm 安装过程失败,请参阅故障排除部分。
Troubleshooting:
故障排除:
If you still have the old version, you may try to install rvm (ruby version manager) via:
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:
source /usr/local/rvm/scripts/rvm; rvm 1.9.3if 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:
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:
rvmsudo gem install [gemname]instead of:
gem install [gemname] # or: sudo gem install [gemname]
如果您仍然拥有旧版本,您可以尝试通过以下方式安装 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.然后如果安装在本地(仅适用于当前用户),请通过以下方式加载 rvm:
source /usr/local/rvm/scripts/rvm; rvm 1.9.3如果是全局的(对于所有用户),则:
sudo bash -c "source /usr/local/rvm/scripts/rvm; rvm 1.9.3"如果您仍然对新的 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.如果你想全局安装一些 gems 并且你已经安装了 rvm,你可以尝试:
rvmsudo gem install [gemname]代替:
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 中的另一个用户以及因此在 sudo 下运行命令时 RVM 为您完成的所有设置都将被忽略(例如 GEM_HOME 等)。所以重申一下,一旦您“sudo”,您就以 root 系统用户身份运行,这将清除您的环境以及它创建的任何文件,您的用户无法修改,并会导致奇怪的事情发生。

