RubyGems的功能类似于Linux下的apt-get。使用它可以方便第从远程服务器下载并安装Rails。

# 安装指定gem包,程序先从本机查找gem包并安装,如果本地没有,则从远程gem安装。
gem install [gemname]

# 仅从本机安装gem包
gem install -l [gemname]

# 仅从远程安装gem包
gem install -r [gemname]

Ruby’s package management system is known as RubyGems, and packages or modules
distributed using RubyGems are called “gems.” RubyGems makes it easy to install Ruby
software and can automatically manage complex dependencies between packages.
The frontend script for RubyGems is gem, and it’s distributed with Ruby 1.9 just as
irb and ri are. In Ruby 1.8, you must install it separately—see http://rubygems.org. Once
the gem program is installed, you might use it like this:
# gem install rails
Successfully installed activesupport-1.4.4
Successfully installed activerecord-1.15.5
Successfully installed actionpack-1.13.5
Successfully installed actionmailer-1.3.5
Successfully installed actionwebservice-1.2.5
Successfully installed rails-1.2.5
6 gems installed
Installing ri documentation for activesupport-1.4.4...
Installing ri documentation for activerecord-1.15.5...
...etc...
As you can see, the gem install command installs the most recent version of the gem
you request and also installs any gems that the requested gem requires. gem has other
useful subcommands as well. Some examples:

gem list # List installed gems

gem enviroment # Display RubyGems configuration information

gem update rails # Update a named gem
gem update # Update all installed gems

gem使用参考手册:http://guides.rubygems.org/

列出远程可安装的gems

如果你运行

gem query —remote # 快捷方式: gem q -R

你会看到所有远程服务器端gem包的详细列表。

简单的输出结果(已被严重简化):

*** REMOTE GEMS ***

 activerecord (0.8.4, 0.8.3, 0.8.2, 0.8.1, 0.8.0, 0.7.6, 0.7.5)
Implements the ActiveRecord pattern for ORM. BlueCloth (0.0.4, 0.0.3, 0.0.2)
BlueCloth is a Ruby implementation of Markdown, a
text-to-HTML conversion tool for web writers.
Markdown allows you to write using an easy-to-read,
easy-to-write plain text format, then convert it to
structurally valid XHTML (or HTML).
..........
.

2.3 搜索远程可安装的gems

如果你运行

 gem query --remote --name-matches doom
# 快捷方式: gem q -R -n doom

你会看到所有的远程服务器上与doom相匹配的gem包详细列表。

简单的输出结果:

*** REMOTE GEMS ***

 ruby-doom (0.8, 0.0.7)
Ruby-DOOM provides a scripting API for creating DOOM
maps. It also provides higher-level APIs to make map
creation easier.

2.4 安装远程gem

如果你运行 (如有必要,在根目录下运行)

gem install --remote progressbar
# 快捷方式: gem i -r progressbar

progressbargem就会安装在你的电脑上。要注意的是你不必指定它的版本,但是如果你一定要指定也可以。因为它默认会自动安装最新的版本。

gem ins -r progressbar-0.0.3

或者

gem ins -r progressbar --version '> 0.0.1'

这两种情况的输出结果都十分简单:

Attempting remote installation of ‘progressbar’Successfully installed progressbar, version 0.0.3

RubyGems允许你安装某个库的不同版本,并在代码中指定实际要使用的版本。

安装命令的其它有用参数是—gen-rdoc,用来生成gem包的RDoc API documentation,以及—run-tests,用来运行的单元测试(如果有单元测试的话)。

还要注意的是,当你远程安装gem包的时候,同时也将下载和安装所有规定的附属文件。你可以尝试着安装copland,然后它会弹出让你也接受log4r的提示(如果你还没安装它的话)。

2.5 查看已经安装的gem

如果你运行

gem specification progressbar
# 快捷方式: gem spec progressbar

你会看到’’progressbar’’ gem的详细内容。

简单的输出结果:

 --- !ruby/object:Gem::Specification
rubygems_version:"1.0\"
name: progressbar
version: !ruby/object:Gem::Version
version: 0.0.3
date: 2004-03-20 20:03:00.679937 +11:00
platform:
summary: "Ruby/ProgressBar is a text progress bar library for Ruby. It can
indicate progress with percentage, a progress bar, and estimated
remaining time."
require_paths:
- lib
files:
- sample/test.rb
- lib/progressbar.rb
- docs/progressbar.en.rd
- docs/progressbar.ja.rd
- ChangeLog
autorequire: progressbar
author: Satoru Takabayashi
email: satoru@namazu.org
homepage: http://namazu.org/~satoru/ruby-progressbar/

这些有趣的信息包括作者的情况,gem的版本和描述。

还有一些让RubyGems正确使用本gem的重要技术提示。它们包括gem包包含的所有文件,从哪里引入文件,以及默认需要的文件 (之后会有更多与此相关的内容)。

2.6 御载gem

如果我们使用完progressbar,可以将它御载。

gem uninstall progressbar

简单的输出结果:

Successfully uninstalled progressbar version 0.0.3

如果这个gem还安装了一个版本,gem命令会询问你想删除哪个版本。

如果有其它的gem需要于这个要被御载的gem,并且没有其它解决办法来替代这个gem,用户将会收到一个警告,并且可以取消此次御载。

2.7 列出所有已经安装的gems

非常简单,运行:

gem query --local
# 快捷方式: 'gem q -L'

2.8 本地和远程操作的注意事项

毫无疑问,你已经注意到 和 —remote出现在目前为止的多数命令行中。如果你不指定它们, gem会尝试本地和远程两个操作。例如:

gem ins rake # 尝试本地安装,如有必要,进行远程安装

gem list -b ^C # 列出所有以“C”开始的本地和远程gems

2.9 浏览所有已安装的gems及其文档

你可以运行自己的gem服务器。这就意味着其它人能(潜在地)安装你电脑上的gems。进而说明你可以在网络浏览器上查看已安装的gem。只需运行:

gem server

然后将页面指向:http://localhost:8808

只要你在安装gem的时候要求生成它的文档,你就能够浏览它们。

2.10 使用配置文件

如果你总是需要为安装的gem生成RDoc documentation文档,并且运行单元测试,你可以在配置文件(home 目录中的.gemrc文件)中指定这些命令行参数。

gem: --rdoc --test

使用配置文件还可以完成其它事情(RDoc 的参数,GEMPATH 的设置)。运行`gem help env`来查看详细内容。

2.11 其它特性

gem check —alien 会报告RubyGems 库中的流氓(不受管理的)文件。

gem check —verify progressbar 会检查已经安装的 ’’progressbar’’ gem对应其校检和是否有效。

参考:

http://article.yeeyan.org/view/130962/95500/

RubyGems使用的更多相关文章

  1. gem install 出现Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org

    在安装了rvm来管理多版本的ruby之后,想在不同环境下安装一些gems,结果gem install puma 之后,发现一次又一次失败. gem install 出现Errno::ECONNRESE ...

  2. rbenv Your user account isn't allowed to install to the system Rubygems

    Clone一个新Rails项目到Mac, bundle install 的时候遇到下面的提示 Fetching source index from http://rubygems.org/ Your ...

  3. 转 关于ruby gem无法连接到rubygems.org的解决方案

    为什么有这个? 由于国内网络原因(你懂的),导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败.所以你会与遇到 gem install rack 或 bundle ...

  4. 淘宝的ruby镜像已无人维护,使用ruby-china的RubyGems镜像

    淘宝的镜像已经无人维护了,参考 https://ruby-china.org/topics/29250 https://gems.ruby-china.org/ 使用新的镜像 $ gem source ...

  5. linux安装ruby ruby-devel rubygems bundler

    linux安装ruby ruby-devel rubygems yum install ruby ruby-devel rubygems 安装bundler gem install bundleror ...

  6. 各个平台 如何安装 Ruby 和 RubyGems

    原文地址:http://cloudfoundry-doc.csdn.net/frameworks/ruby/installing-ruby.html Last Updated: 2012-11-01 ...

  7. Linux 离线安装Rubygems详解

    很多时候我们会发现,真实的生成环境很多都没有外网,只有内网环境,这个时候我们又需要安装RubyGems,则不能提供yum命令进行在线安装了,这个时候我们就需要下载安装包进行离线安装.本文主要简单介绍如 ...

  8. 关于ruby gem无法连接到rubygems.org的解决方案

    RubyGems 镜像 - 淘宝网 为什么有这个? 由于国内网络原因(你懂的),导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败.所以你会与遇到 gem ins ...

  9. RubyGems系列之创建自己的gem

    转载请注明来源:https://www.cnblogs.com/zhanggui/p/9720818.html 一. 前言 我们可以在rubygems.org中下载安装他人创建的gem.现在,我们尝试 ...

随机推荐

  1. react环境搭建

    react-webpack文件夹是开发目录,在此目录下执行命令,假设你已经正确安装了 nodejs 一:参照教程搭建环境 https://github.com/newtriks/generator-r ...

  2. (转)CSS字体大小: em与px、pt、百分比之间的对比

    CSS样式最混乱的一个方面是应用程序中文本扩展的font-size属性.在CSS中,你可以用四个不同的单位度量来显示在web浏览器中的文本 大小.这四个单位哪一种最适合Web? 这个问题引起了广泛的争 ...

  3. C++编程注意事项

    1.所有成员变量在构造函数中进行初始化操作,如指针赋值为空,bool赋值为FALSE(默认为TRUE); 2.构造函数与析构函数配对出现,执行反向操作,保证执行析构之后,没有遗留问题存在: 3.如果需 ...

  4. oracle 11g 64位安装sqldeveloper打开不了

    oracle 11g 64位安装sqldeveloper打开不了解决方法: 1.到官网下载对应版本的sqldeveloper. 2.找对应安装路径下的F:\app\Administrator\prod ...

  5. @property在内存管理中的参数问题

    // // Created by wanghy on 15/8/14. // // /* retain : release旧值,retain新值(用于OC对象),要配合nonatomic使用. ass ...

  6. WPF TreeView递归遍历相关方法

    /// <summary> /// 递归改变组织树选中状态. /// </summary> /// <param name="org">< ...

  7. You have new mail in /var/spool/mail/root 烦不烦你(转)

    转自(http://blog.csdn.net/yx_l128125/article/details/7425182) 有时在进入系统的时候经常提示You have new mail in /var/ ...

  8. Fedora 21 安装QQ国际版

    首先安装依赖包 sudo yum install freetype.i686 libpng.i686 libgcc.i686 libXau.i686 点击下载wine-2012qq国际版 unzip ...

  9. c语言"a<b<c"条件值的判定

    示例代码: #include <stdio.h> int main() { , b = , c = ; ; while (a<b<c) { t = a; a = b; b = ...

  10. sar监控系统状态

    sar 命令很强大,它可以监控系统所有资源状态,比如平均负载.网卡流量.磁盘状态.内存使用等等. 它不同于其他系统状态监控工具的地方在于,它可以打印历史信息,可以显示当天从零点开始到当前时刻的系统状态 ...