The simplest way to distribute a gem for public consumption is to
use RubyGems. Gems that are published to RubyGems can be
installed via the gem install
command or through the use of tools
such as Bundler.
To begin, you’ll need to create an account on RubyGems.org. Visit the sign up page and supply an email address that you control, a handle (username) and a password.
El " handle" que te solicita es tu nombre de usuario (loginname).
After creating the account, use your email and password when pushing
the gem. (rubygems saves the credentials in ~/.gem/credentials
for
you so you only need to log in once.)
~]$ cat .gem/credentials --- :rubygems_api_key: XXXXXXXXXXXXXXXXXXXXXXXXYYYYYYYY [~]$
[/tmp/tutu/my_gem]$ gem build my_gem.gemspec WARNING: no homepage specified Successfully built RubyGem Name: my_gem Version: 0.0.1 File: my_gem-0.0.1.gem
o bien podemos usar rake build
.
para contruir la gema.
0.1.0
of a new gem named squid-utils
:
$ gem push squid-utils-0.1.0.gem Enter your RubyGems.org credentials. Don't have an account yet? Create one at https://rubygems.org/sign_up Email: gem_author@example Password: Signed in. Pushing gem to RubyGems.org... Successfully registered gem: squid-utils (0.1.0) Congratulations! Your new gem is now ready for any ruby user in the world to install!
We can also use rake release
:
[/tmp/tutu/my_gem]$ rake -T rake build # Build my_gem-0.0.1.gem into the pkg directory rake install # Build and install my_gem-0.0.1.gem into system gems rake release # Create tag v0.0.1 and build and push my_gem-0.0.1.gem to Rubygems
Para instalarla podemos hacer uso de gem install
:
[/tmp/tutu/my_gem]$ gem install ./my_gem-0.0.1.gem Successfully installed my_gem-0.0.1 1 gem installedo bien
rake install
.
Para desinstalarla:
[/tmp/tutu]$ gem uninstall --force my_gem Successfully uninstalled my_gem-0.0.1 [/tmp/tutu]$ pry [1] pry(main)> require 'my_gem' LoadError: cannot load such file -- my_gem from /Users/casiano/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' [2] pry(main)>