I want my app to not be able to use any installed gems. Is there a ruby 1.9 startup parameter or way of doing this programmatically?
-
2what are you trying to achieve with that? – phoet Oct 17 '12 at 20:30
-
How would your app use any gems unless you tell it to do so? Seems like not adding any `require`-type commands would solve the problem. It also seems like a user invoking the Ruby interpreter could use '`-r`' and force Ruby to load something, whether your code says to or not. – the Tin Man Oct 18 '12 at 03:42
-
I want to ensure that I am never using any system gems--only local files, in my run (to prepare my app for distribution). – rogerdpack Oct 18 '12 at 19:39
-
1[You caused the addition of a Ruby startup parameter](http://bugs.ruby-lang.org/issues/7184)! – steenslag Oct 25 '12 at 00:24
2 Answers
ruby --disable-gems
is the MRI (1.9) commandline parameter. "It prevents the addition of gem installation directories to the default load path". (The Ruby Programming Language, p. 391)
Edit 25-10-2012: Ruby core had the same idea as @rogerdpack in the comments and added the more verbose ruby --help
parameter. Ruby revision!

- 79,051
- 16
- 138
- 171
-
Flabberghasting that ruby -h doesn't output this, nor offer you a 'verbose' option for it. yikes. – rogerdpack Oct 18 '12 at 19:38
-
1@rogerdpack Yes that's weird. Reported [as a bug](http://bugs.ruby-lang.org/issues/7184). – steenslag Oct 18 '12 at 21:17
-
Jorg W Mittag has a more verbose comment on `--disable-gems` at http://stackoverflow.com/a/3253995/38765 – Andrew Grimm Oct 18 '12 at 22:46
Looking at the rubygems configuration file, I would attempt to hack out gempath
or gemhome
to see if you can override (instead of just append to) defaults.
If, for example, setting gempath
to be empty, or to point to /dev/null
, prevents using system gems, then that would be the way to go.
The main advantage to this, as I see it, is that your anti-rubygems config file can be passed to ruby 1.9 as a startup parameter (so not coded in), well documented, and checked into your repository.
All of this is, of course, disregarding that rubygems is part of ruby 1.9's standard library - so ruby may choke and die if it can't have access to its gems, depending on how much of ruby's base install requires gem functionality. YMMV.

- 10,434
- 1
- 36
- 45
-
that is a fascinating idea--just tweak the gempath in the script. genius! – rogerdpack Oct 18 '12 at 19:38