rubygem若干常用选项参数

来源:互联网 发布:win10上安装mac虚拟机 编辑:程序博客网 时间:2024/06/05 17:18

    可以用gem help commands看所有支持的参数,这个比gem -h显示的全:

wisy@wisy-ThinkPad-X61:~/src/ruby_src$ gem help commandsGEM commands are:    build             Build a gem from a gemspec    cert              Manage RubyGems certificates and signing settings    check             Check a gem repository for added or missing files    cleanup           Clean up old versions of installed gems    contents          Display the contents of the installed gems    dependency        Show the dependencies of an installed gem    environment       Display information about the RubyGems environment    fetch             Download a gem and place it in the current directory    generate_index    Generates the index files for a gem server directory    help              Provide help on the 'gem' command    install           Install a gem into the local repository    list              Display local gems whose name starts with STRING    lock              Generate a lockdown list of gems    mirror            Mirror all gem files (requires rubygems-mirror)    outdated          Display all gems that need updates    owner             Manage gem owners of a gem on the push server    pristine          Restores installed gems to pristine condition from files                      located in the gem cache    push              Push a gem up to the gem server    query             Query gem information in local or remote repositories    rdoc              Generates RDoc for pre-installed gems    search            Display remote gems whose name contains STRING    server            Documentation and gem repository HTTP server    sources           Manage the sources and cache file RubyGems uses to search                      for gems    specification     Display gem specification (in yaml)    stale             List gems along with access times    uninstall         Uninstall gems from the local repository    unpack            Unpack an installed gem to the current directory    update            Update installed gems to the latest version    which             Find the location of a library file you can require    yank              Remove a pushed gem from the indexFor help on a particular command, use 'gem help COMMAND'.Commands may be abbreviated, so long as they are unambiguous.e.g. 'gem i rake' is short for 'gem install rake'.

windows下gem search默认是查找本地的gem,需要加-R以便查找远程的gem;linux like系统正好相反,默认是查找远程gem,如果要查找本地gem要加--local(或者-l).查询还可以用query选项,和search差不多.

gem list列出本地安装的第三方gem,可以用gem which查看某一个gem的路径:

wisy@wisy-ThinkPad-X61:~/src/ruby_src$ gem list*** LOCAL GEMS ***activemodel (4.1.8)activerecord (4.1.8)activesupport (4.1.8)arel (6.0.0, 5.0.1.20140414130214)bigdecimal (1.2.5, 1.2.4)builder (3.2.2)i18n (0.7.0.beta1)io-console (0.4.2)json (1.8.1)md5sum (1.0.2)minitest (5.4.3, 4.7.5)net-ntp (2.1.2)power_assert (0.2.2)psych (2.0.8, 2.0.5)rake (10.4.2, 10.1.0)rdoc (4.2.0, 4.1.0)RubyInline (3.12.3)test-unit (3.0.8, 2.1.3.0)thread_safe (0.3.4)tzinfo (1.2.2)webrick (1.3.1)ZenTest (4.11.0)zip (2.0.2)wisy@wisy-ThinkPad-X61:~/src/ruby_src$ gem which zip/var/lib/gems/2.1.0/gems/zip-2.0.2/lib/zip.rb

如果要看一个gem的详细信息,可以用gem specification,不过返回的是yaml格式,不过ruby中可以轻松将yaml转换为obj,从而用pp显示其"人类可读"内容:

wisy@wisy-ThinkPad-X61:~/src/ruby_src/drb$ gem specification zip>zip.docruby -e"require 'yaml';require 'pp';pp YAML::load(File.read('zip.doc'))"Gem::Specification.new do |s|  s.name = "zip"  s.version = Gem::Version.new("2.0.2")  s.installed_by_version = Gem::Version.new("0")  s.authors = ["Postmodern", "Thomas Sondergaard", "Sam Lown"]  s.date = Time.utc(2010, 5, 26)  s.description = "zip is a Ruby library for reading and writing Zip files. Unlike the official rubyzip, zip is compatible with Ruby 1.9.1."  s.email = ["me@samlown.com", "postmodern.mod3@gmail.com"]  s.extra_rdoc_files = ["ChangeLog.txt", "README"]  s.files = ["ChangeLog.txt", "README"]  s.homepage = "http://github.com/postmodern/rubyzip2"  s.rdoc_options = ["--charset=UTF-8"]  s.require_paths = ["lib"]  s.rubygems_version = "2.2.2"  s.specification_version = 4  s.summary = "zip is a Ruby library for reading and writing Zip files"  end

其实specification本身带有一个--ruby输出选项,输出和上面类似:gem specification zip --ruby,如果想查询远程gem的信息可以在后面加-r选项:gem specification xxx_gem --ruby -r

使用install可以从远程安装gem,不过有时候rubygems.org卡的和屎一样,这时要不你用代理,要不你从其他地方下载下来从本地安装:gem install --local xxx_gem.gem

可以用gem 查看某个gem的所有相关文件:

wisy@wisy-ThinkPad-X61:~/src/ruby_src/drb$ gem contents zip/var/lib/gems/2.1.0/gems/zip-2.0.2/ChangeLog.txt/var/lib/gems/2.1.0/gems/zip-2.0.2/NEWS.txt/var/lib/gems/2.1.0/gems/zip-2.0.2/README/var/lib/gems/2.1.0/gems/zip-2.0.2/Rakefile/var/lib/gems/2.1.0/gems/zip-2.0.2/TODO.txt/var/lib/gems/2.1.0/gems/zip-2.0.2/lib/zip.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/lib/zip/ioextras.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/lib/zip/stdrubyext.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/lib/zip/tempfile_bugfixed.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/lib/zip/version.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/lib/zip/zip.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/lib/zip/zipfilesystem.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/lib/zip/ziprequire.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/samples/example.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/samples/example_filesystem.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/samples/gtk_zip.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/samples/write_simple.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/samples/zipfind.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/test/alltests.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/test/data/file1.txt/var/lib/gems/2.1.0/gems/zip-2.0.2/test/data/file1.txt.deflatedData/var/lib/gems/2.1.0/gems/zip-2.0.2/test/data/file2.txt/var/lib/gems/2.1.0/gems/zip-2.0.2/test/data/notzippedruby.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/test/data/rubycode.zip/var/lib/gems/2.1.0/gems/zip-2.0.2/test/data/rubycode2.zip/var/lib/gems/2.1.0/gems/zip-2.0.2/test/data/testDirectory.bin/var/lib/gems/2.1.0/gems/zip-2.0.2/test/data/zipWithDirs.zip/var/lib/gems/2.1.0/gems/zip-2.0.2/test/gentestfiles.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/test/ioextrastest.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/test/stdrubyexttest.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/test/zipfilesystemtest.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/test/ziprequiretest.rb/var/lib/gems/2.1.0/gems/zip-2.0.2/test/ziptest.rb

最后可以用gem update升级所有本地gem,也可以用gem outdated查看本地需要升级的gem.

0 0
原创粉丝点击