Ruby学习札记(3)- Ruby中gem的安装与卸载

Ruby学习札记(3)- Rubygem的安装与卸载

 

Ruby中有gem包这种概念,类似PHP中的pear,相当于一种插件。具体可以Google一下。

  (1)查看已经安装的gem

如果安装Ruby(我用的是Ruby1.9.2)时,勾选了“Add Ruby executables to your PATH”选项,那么可以在CMD中直接输入gem list列出本地已安装的gems

C:/>gem list *** LOCAL GEMS *** minitest (1.6.0) rake (0.8.7) rdoc (2.5.8)

可以看到已经有3gem

如果安装时没有勾选,也没有关系,在“开始”菜单上,找到“Ruby 1.9.2-p180->Start Command Prompt with Ruby”,打开它,就会出现有Ruby环境的CMD

 

   (2)查询服务器端可用的gem

命令:gem query –remote,简写为gem q –R

结果如下:

*** 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). captcha (0.1.2) Ruby/CAPTCHA is an implementation of the 'Completely Automated Public Turing Test to Tell Computers and Humans Apart'. cardinal (0.0.4) Ruby to Parrot compiler. cgikit (1.1.0) CGIKit is a componented-oriented web application framework like Apple Computers WebObjects. This framework services Model-View-Controller architecture programming by components based on a HTML file, a definition file and a Ruby source. progressbar (0.0.3) Ruby/ProgressBar is a text progress bar library for Ruby. It can indicate progress with percentage, a progress bar, and estimated remaining time. rake (0.4.0, 0.3.2) Ruby based make-like utility.

 

   (3)在线安装gem

命令:gem install (gem-name)

回车之后,要等一等,无论是否安装成功,都会有提示信息。如果网速很慢,会一直停在这一行,这时就不要把CMD关了。

C:/Users/wesley_chen/dbi-0.4.3>gem install mysql Fetching: mysql-2.8.1-x86-mingw32.gem (100%) Successfully installed mysql-2.8.1-x86-mingw32 1 gem installed Installing ri documentation for mysql-2.8.1-x86-mingw32... Installing RDoc documentation for mysql-2.8.1-x86-mingw32...

安装好的gem默认位置在Ruby安装目录/ lib/ruby/gems/1.9.1,下面有4个目录cachedocgemsspecification,根据目录名差不多知道大概的作用。

 

   (4)离线安装gem

http://rubygems.org/上会发布gem,有个技巧就是知道要安装的gem的名字,例如名字为deprecatedgem,那么在浏览器中输入http://rubygems.org/gems/deprecatedgem名字)就可以查询名为deprecatedgem所有版本,只要把“deprecated”换成其他gem的名字就可以了。

下载gem后,在CMD中切换到gem所在目录中,输入一下命令:

gem install ./(gem-name) --local

结果如下:

C:/Users/wesley_chen>gem install ./deprecated-3.0.0.gem --local Successfully installed deprecated-3.0.0 1 gem installed Installing ri documentation for deprecated-3.0.0... Installing RDoc documentation for deprecated-3.0.0... C:/Users/wesley_chen>gem list *** LOCAL GEMS *** deprecated (3.0.0) minitest (1.6.0) rake (0.8.7) rdoc (2.5.8)

 

    (4)卸载gem

命令:gem uninstall (gem-name)

一般先用gem list查看一下,找到要卸载的gem的名字。

C:/>gem uninstall deprecated Successfully uninstalled deprecated-3.0.0

如果安装了多个版本,会出现以下提示

C:/Users/wesley_chen>gem list *** LOCAL GEMS *** dbi (0.4.3) deprecated (3.0.0, 2.0.1) minitest (1.6.0) rake (0.8.7) rdoc (2.5.8) C:/Users/wesley_chen>gem uninstall deprecated Select gem to uninstall: 1. deprecated-2.0.1 2. deprecated-3.0.0 3. All versions > 1 Successfully uninstalled deprecated-2.0.1

如果卸载的gem依赖其他的gem,会有以下提示信息

C:/Users/wesley_chen>gem uninstall deprecated You have requested to uninstall the gem: deprecated-3.0.0 dbi-0.4.3 depends on [deprecated (>= 2.0.0)] If you remove this gems, one or more dependencies will not be met. Continue with Uninstall? [Yn] y Successfully uninstalled deprecated-3.0.0

你可能感兴趣的:(I,-,初学Ruby)