Python has its eggs, Java has its jars and ruby has its gems. So a gem is a ruby package, containing some library or executable program. In the previous two chapters about RVM and Rbenv I installed rails using the gem command. Since ruby 1.9, Ruby Gems comes with ruby. So, how to use it?
- You can list all the available gems, hosted on RubyGems.org with:
gem query --remote (gem q -r) or gem list -r
- You can search for remote gems with:
gem query --remote --name-matches <name> or gem search -r <name> or gem search <name> or gem sea <name>
- You can install a gem using:
gem install --remote <name> or gem install <name> or gem ins <name>
- You can install a given version of a gem using:
gem install --remote <name> --version <version> or gem install <name> --version <version> or gem ins <name> --version <version> or like that gem install <name>-<version>
For versions you can use operators :
gem install <name> --version "= 0.1.3" All operators: = Equals version != Not equal to version > Greater than version < Less than version >= Greater than or equal to <= Less than or equal to ~> Approximately greater than
To see all available versions of a gems:
gem search -a <name> or gem list -r -a
- To see the locally installed gems:
gem list (-l) or gem query -l (--local)
To search in the locally installed gems for given gem:
gem search -l <name>
A detailed information for an installed gem:
gem specification <name>
This can be executed with the ‘-r’ option for remote gem.
A cool feature is to run
And to use your browser, opening http://localhost:8808 to browse detailed information for your installed gems.
- To uninstall a gem:
gem uninstall <name>
- You can install gems with options like ‘–no-rdoc‘ or ‘no-ri’, see all available using:
gem help install
You can put a .gemrc file in your home with some commands and settings to be used with Ruby Gems. The file should look like this:
gem: --local --no-rdoc --run-tests gempath: - /usr/share/rubygems - /home/meddle/.stuff
Read for more here http://docs.rubygems.org/read/chapter/11
I think this is a good manual for the tool, we will use it a lot in the up-coming posts.