使用命令行gem工具,如何安装特定版本的gem?
当前回答
您可以使用-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]
其他回答
使用-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
对于Ruby 1.9+使用冒号。
gem install sinatra:1.4.4 prawn:0.13.0
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.
推荐文章
- Rails中的OO设计:在哪里放置东西
- 给定一个类,查看实例是否有方法(Ruby)
- 在日历应用程序中建模重复事件的最佳方法是什么?
- 如何创建一个私有类方法?
- 无法安装pg gem
- 双* (splat)操作符做什么
- 如何使用Ruby on Rails进行HTTP请求?
- 如何从rake任务中提前返回?
- 什么&。(&点)在Ruby中是什么意思?
- 是什么阻碍了Ruby和Python获得V8的Javascript速度?
- 运行pod设置给我“坏的解释器:没有这样的文件或目录”错误
- 在Ubuntu上安装sqlite3-ruby错误
- Ruby有什么Python没有的,反之亦然?
- find_spec_for_exe':无法找到gem bundle (>= 0.a) (gem::GemNotFoundException)
- 将字符串转换为可符号的ruby