Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to call ruby1.9 without loading rubygems?

So ruby 1.9 is really nice in that it'll automatically require rubygems, and hence when you call require 'somegem' without first requiring rubygems it'll work, and that's generally awesome.

But I have a ton of shell scripts using ruby, and they generally don't rely on rubygems. Shell tools should run instantly, and loading rubygems for nothing is a major drag, mostly because it involves a bunch of disk operations with scattered small files.

I want to be able to tell ruby, when running these shell scripts, to skip loading gems. Ideally, something like #!ruby --no-rubygems in the shebang line.

Is there such a thing? Or maybe a compile option that'll tell ruby rubygems must be required manually?

like image 463
kch Avatar asked Jul 15 '10 06:07

kch


1 Answers

Yes, you can use the --disable-gems option.

Note that whether or not passing options in the shebang line works depends on your operating system. Some operating systems don't support passing options at all, some only support passing one option or argument.

So, if you have for example

#!/usr/bin/env ruby

Then it's pretty unlikely that you will be able to attach the option to the end. If OTOH you change that to

#!/usr/local/bin/ruby --disable-gems

Then you have hardwired the location of the Ruby binary into your script.

And of course there are operating systems that don't interpret shebang lines at all. (After all, they were never specified in any standard, and aren't even properly documented.)

An alternative would be to set the RUBYOPT environment variable in your shell environment and simply switch to a different environment with RUBYOPT unset (or set to -w, my personal favorite) for your Ruby development.

like image 138
Jörg W Mittag Avatar answered Nov 15 '22 17:11

Jörg W Mittag