Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent gem pushes to RubyGems

Tags:

ruby

rubygems

NPM has the ability to prevent a gem from being published. Is there a way to do the same thing and prevent a gem from being accidentally published to rubygems?

like image 826
Jason Waldrip Avatar asked Jun 17 '13 21:06

Jason Waldrip


People also ask

What is require RubyGems?

require 'rubygems' will adjust the Ruby loadpath allowing you to successfully require the gems you installed through rubygems, without getting a LoadError: no such file to load -- sinatra .

Where are RubyGems stored?

When you use the --user-install option, RubyGems will install the gems to a directory inside your home directory, something like ~/. gem/ruby/1.9. 1 . The commands provided by the gems you installed will end up in ~/.

Is RubyGems included with Ruby?

Ruby comes with RubyGems by default since version 1.9, previous Ruby versions require RubyGems to be installed by hand.


1 Answers

RubyGems 2.2.0 was only recently released, which adds support for this. You need to set allowed_push_host to your own gem server. The documentation describes it thus:

If you want to control who can install a gem, or directly track the activity surrounding a gem, then you’ll want to set up a private gem server. You can set up your own gem server or use a commercial service such as Gemfury.

RubyGems 2.2.0 and newer support the allowed_push_host metadata value to restrict gem pushes to a single host. If you are publishing private gems you should set this value to prevent accidental pushes to rubygems.org:

Gem::Specification.new 'my_gem', '1.0' do |s|
  # ...
  s.metadata['allowed_push_host'] = 'https://gems.my-company.example'
end

To upgrade RubyGems, just run the following command:

gem update --system
like image 181
mrlee Avatar answered Sep 28 '22 10:09

mrlee