使用命令行gem工具,如何安装特定版本的gem?
当前回答
对于Ruby 1.9+使用冒号。
gem install sinatra:1.4.4 prawn:0.13.0
其他回答
安装 安装Gem -v版本号
对于卸载 Gem卸载gemname -v versionnumber
对于Ruby 1.9+使用冒号。
gem install sinatra:1.4.4 prawn:0.13.0
您可以使用-v或——version标志。例如
gem install bitclock -v '< 0.0.2'
要指定上下版本边界,可以指定——version标志两次
gem install bitclock -v '>= 0.0.1' -v '< 0.0.2'
或者使用语法(例如)
gem install bitclock -v '>= 0.0.1, < 0.0.2'
另一种方法是
gem install bitclock:'>= 0.0.1'
但是对于最后一个选项,不可能同时指定上边界和下界。
[gem 3.0.3和ruby 2.6.6]
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
推荐文章
- 如何从Ruby数组中创建平均值?
- 如何在ruby中做一个安全的连接路径名?
- 在OS X 10.9+上安装libv8 gem
- Ruby中没有增量操作符(++)?
- 如何得到一个特定的输出迭代哈希在Ruby?
- Ruby正则表达式中\A \z和^ $的区别
- __FILE__在Ruby中是什么意思?
- Paperclip::Errors::MissingRequiredValidatorError with Rails
- Ruby:如何将散列转换为HTTP参数?
- 在ROR迁移期间,将列类型从Date更改为DateTime
- 把一个元素推到数组开头最简单的方法是什么?
- ActiveRecord:大小vs计数
- Ruby的dup和克隆方法有什么区别?
- 我怎么才能跳出露比·普利的怪圈?
- Rails:在大数字中添加逗号有Rails技巧吗?