Goodbye ubygems

source code form

No we're not hating on RubyGems. This is about ubygems and that's not a typo. There was a file named ubygems.rb and it has been removed from Ruby 2.5.

Back in the day, RubyGems didn't ship with Ruby. You have to install it separately. To use RubyGems, you need to require it like any other Ruby code. You'd write require 'rubygems' before using it.

Ruby provides the -r switch on the command line. Here's the description.

  -rlibrary       require the library before executing your script

-r is used to require the library from the command line without needing to require it inside your script.

The switch -rubygems looks for a file named ubygems.rb. There was no separate -rubygems switch. This is just the -r switch with ubygems as the library.

The file is actually just one line: require 'rubygems'. It didn't really have a use aside from -rubygems looking better than -rrubygems. Starting with Ruby 1.9, RubyGems ships built-in with Ruby so you don't have to use either.

The code below doesn't work on Ruby 2.5 anymore though it works on Ruby 2.4 and earlier. But there's probably not too many code using the -rubygems from the command line.

ruby -rubygems -e 'puts 1'

Traceback (most recent call last):
    1: from /Users/crigor/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/crigor/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- ubygems (LoadError)
Ruby on Rails

Start a Free Trial:

Engine Yard is so much more than just a Ruby on Rails PaaS platform. But don't just take our word for it. Request a free trial of Engine Yard platform today, and one of our Engineers will be in contact within one business day to get you going.


Related posts


Subscribe to our Blog