Ruby RubyGems

Ruby 教程 · 2019-02-19 12:58:19

RubyGems 是 Ruby 的一个包管理器,它提供一个分发 Ruby 程序和库的标准格式,还提供一个管理程序包安装的工具。

RubyGems 旨在方便地管理 gem 安装的工具,以及用于分发 gem 的服务器。这类似于 Ubuntu 下的apt-get, Centos 的 yum,Python 的 pip。

RubyGems大约创建于2003年11月,从Ruby 1.9版起成为Ruby标准库的一部分。

如果你的 Ruby 低于 1.9 版本,也可以通过手动安装:

更新 RubyGems 命令:

$ gem update --system          # 需要管理员或root用户

Gem

Gem 是 Ruby 模块 (叫做 Gems) 的包管理器。其包含包信息,以及用于安装的文件。

Gem通常是依照".gemspec"文件构建的,包含了有关Gem信息的YAML文件。Ruby代码也可以直接建立Gem,这种情况下通常利用Rake来进行。

gem命令

gem命令用于构建、上传、下载以及安装Gem包。

gem用法

RubyGems 在功能上与 apt-get、portage、yum 和 npm 非常相似。

安装:

gem install mygem

卸载:

gem uninstall mygem

列出已安装的gem:

gem list --local

列出可用的gem,例如:

gem list --remote

为所有的gems创建RDoc文档:

gem rdoc --all

下载一个gem,但不安装:

gem fetch mygem

从可用的gem中搜索,例如:

gem search STRING --remote

gem 包的构建

gem命令也被用来构建和维护.gemspec和.gem文件。

利用.gemspec文件构建.gem:

gem build mygem.gemspec

修改国内源

由于国内网络原因(你懂的),导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败。

所以你会与遇到 gem install rack 或 bundle install 的时候半天没有响应,具体可以用 gem install rails -V 来查看执行过程。

因此我们可以将它修改为淘宝下载源: http://ruby.taobao.org/

首先,查看当前源:

$ gem sources -l
*** CURRENT SOURCES ***

https://rubygems.org/

接着,移除https://rubygems.org/,并添加淘宝下载源 http://ruby.taobao.org/。

$ gem sources --remove https://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l
*** CURRENT SOURCES ***

https://ruby.taobao.org
# 请确保只有 ruby.taobao.org
$ gem install rails

如果你使用 Gemfile 和 Bundle (例如:Rails 项目)

你可以用bundle的gem源代码镜像命令。

$ bundle config mirror.https://rubygems.org https://ruby.taobao.org

这样你不用改你的 Gemfile 的 source。

source 'https://rubygems.org/'
gem 'rails', '4.1.0'
...

点击查看所有 Ruby 教程 文章: https://codercto.com/courses/l/16.html

查看所有标签

RESTful Web Services Cookbook

RESTful Web Services Cookbook

Subbu Allamaraju / Yahoo Press / 2010-3-11 / USD 39.99

While the REST design philosophy has captured the imagination of web and enterprise developers alike, using this approach to develop real web services is no picnic. This cookbook includes more than 10......一起来看看 《RESTful Web Services Cookbook》 这本书的介绍吧!

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具