使用命令行gem工具,如何安装特定版本的gem?
当前回答
在安装之前,可以使用list命令检查可用的版本。
gem list ^[gemname]$ --remote --all
gem install [gemname] -v [version]
其他回答
您可以使用-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.
在安装之前,可以使用list命令检查可用的版本。
gem list ^[gemname]$ --remote --all
gem install [gemname] -v [version]
对于Ruby 1.9+使用冒号。
gem install sinatra:1.4.4 prawn:0.13.0
正如其他人所注意到的,通常情况下,gem安装命令使用-v标志。
如果你在本地开发宝石,从你的宝石规格中切割宝石后:
$ gem install gemname-version.gem
假设版本是0.8,它看起来是这样的:
$ gem install gemname-0.8.gem
推荐文章
- 如何找到包含匹配值的哈希键
- 未初始化的常量ActiveSupport::Dependencies::Mutex (NameError)
- 如何在Rails中找到当前的路由?
- 在Ruby中->运算符叫什么?
- Rails参数解释?
- Ruby中DateTime和Time的区别
- 如何从代理服务器后面更新Ruby Gems (ISA-NTLM)
- 如何用另一个键替换哈希键
- attr_accessor和attr_accessible的区别
- 如何从Ruby文件路径中获得没有扩展名的文件名
- rvm安装失败:“rvm不是一个函数”
- rmagick gem安装“无法找到Magick-config”
- 学习Ruby on Rails
- Ruby中的数组切片:解释不合逻辑的行为(摘自Rubykoans.com)
- 如何分割一个带分隔符的字符串在Ruby和转换为一个数组?