使用命令行gem工具,如何安装特定版本的gem?
当前回答
Linux
要安装不同版本的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
然后安装:
$ sudo apt-get install ruby=1:1.9.3
要查看当前版本,运行:
$ gem --version # Check for the current user.
$ sudo gem --version # Check globally.
如果版本仍然是旧的,你可以尝试使用ruby版本管理器(rvm)切换到新的版本:
rvm 1.9.3
注意:如果rvm是全局安装的,则可以使用sudo作为前缀。如果rvm命令不在全局路径中,则运行/usr/local/rvm/scripts/rvm。如果rvm安装过程失败,请参考故障处理。
故障排除:
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.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: 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]
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.
其他回答
使用-v标志:
$ gem install fog -v 1.8
在安装之前,可以使用list命令检查可用的版本。
gem list ^[gemname]$ --remote --all
gem install [gemname] -v [version]
正如其他人所注意到的,通常情况下,gem安装命令使用-v标志。
如果你在本地开发宝石,从你的宝石规格中切割宝石后:
$ gem install gemname-version.gem
假设版本是0.8,它看起来是这样的:
$ gem install gemname-0.8.gem
安装 安装Gem -v版本号
对于卸载 Gem卸载gemname -v versionnumber
对于Ruby 1.9+使用冒号。
gem install sinatra:1.4.4 prawn:0.13.0
推荐文章
- 是否可以在MiniTest中运行单个测试?
- 如何在Ruby中生成a和b之间的随机数?
- 无法安装gem -未能建立gem本地扩展-无法加载这样的文件——mkmf (LoadError)
- 如何在Ruby中创建文件
- 什么是Ruby文件。开放模式和选项?
- Ruby数组到字符串的转换
- 如何分割(块)一个Ruby数组成X元素的部分?
- Ruby中“or”和||的区别?
- 如何测试参数是否存在在轨道
- 库未加载:libmysqlclient.16。在OS X 10.6上使用mysql2 gem运行'rails server'时出现dylib错误
- 在Ruby中不创建新字符串而修饰字符串的规范方法是什么?
- RVM不是一个函数,用' RVM use…’不会起作用
- 了解Gemfile。锁文件
- 如何确定一个数组是否包含另一个数组的所有元素
- 是什么导致这个ActiveRecord::ReadOnlyRecord错误?