RubyGems Frequently Asked Questions
Basic Questions
Why did you create this thing?
Because we needed it! And needed it badly.
Is this the same RubyGems that was presented at RubyConf 2001?
No. It is based on the same idea, but the code was written from scratch (initially) at RubyConf 2003.
Security Issues
Doesn’t this open a huge security hole? How can I trust the Gems which are automatically downloaded from the net?
The same way you can trust all other code you install. (I.e. ultimately, you can’t.) : Gems are not automatically downloaded from the ‘net, they are manually downloaded from the ‘net. It’s essentially the same as grabbing a tarball from the RAA or RubyForge, but easier. The “automatic dependency” resolution prompts you for confirmation before installing anything.
How well does RubyGems play with other packaging systems?
It’d be nice to package code as a Gem, and then have it easily portable to many packaging systems (e.g. manual, RubyGems, dpkg/apt-get and other distro specific packaging). A quick glance at RubyGems suggests that installation of a package as a Gem requires all of its dependencies to be gems also (due to require_gem). Thoughts on this?
It would not be too difficult to create a convertor to auto-generate dpkg or rpm files out of gems. It has been on the TODO list since day 1, but it hasn’t yet made it to the top of anyone’s priority list. Anyone who would like to do this for one or more packaging systems is more than welcome!
From Eivind Eklund:
I believe this is undoable inside the required structures for most other packaging systems (based on the Filesystem Hierarchy Standard). FreeBSD and Debian at least requires following a structure that is different from and not compatible with one directory per gem. I believe the same requirements exists for other package repositories (Fedora, NetBSD, OpenBSD, at least), but have not looked at them in detail recently enough to remember with certainity. Automatic repackaging for RPA is undoable because RPA requires that the packages can be re-exported in the formats required by other packaging systems. (Oh, and I would LOVE to be proved wrong on this.)
AllInOneRuby and RubyScript2Exe Compatibility
Is it possible (or is there a plan) to use RubyGems with AllInOneRuby or RubyScript2Exe?
It would seem so. Erik has been hard at work adding RubyGems support for both of those tools, and the current versions have both been successfully used with some gems.
Where I can get the latest yaml metadata used by rubygems?
Here (http://gems.rubyforge.org/yaml)
Where can I find out more about RubyGems?
Here are a couple of resources:
Installation Questions
Error: Could not find RubyGem sources (> 0.0.0)
I installed rubygems 0.8.3 and get the following error when trying to run the gem command: Could not find RubyGem sources (> 0.0.0). What’s wrong?
You may have been bitten by a 0.8.3 install bug. Try installing 0.8.7 or above.
Error “No such file to load—rubygems/builder (LoadError)”
During a fresh install of RubyGems, I get the following error … “in ‘require’: No such file to load—rubygems/builder (LoadError)”. What’s wrong?
Check to see that you have all the libraries needed by rubygems/builder. Missing libzlib-ruby or libyaml-ruby in particular can cause this error.
Debian Linux users may also need to apt-get install libdrb-ruby and liberb-ruby and rdoc.
Authenticating Windows Proxy Problems
How can I install a gem from behind a Windows proxy that requires authentication? I’ve tried username(colon)password(at)proxyaddress in the—http-proxy url but that doesn’t seem to work.
This suggests you’re behind an MS Proxy that does NTLM authentication. The proxy support in Ruby is currently only for Basic authentication.
A workaround is to install http://apserver.sourceforge.net apserver on your local machine, configure it and run gems through this proxy.
- Install: Just download apserver 097 (and not the experimental 098!) and unpack.
- Configure: Edit the server.cfg file and put the values for your MS proxy in PARENT_PROXY and PARENT_PROXY_PORT. Enter the values for DOMAIN and USER. Leave PASSWORD blank (nothing after the colon) – you will be prompted when launching it.
- Run apserver: cd aps097; python main.py
- Run Gems: gem install—http-proxy http://localhost:5865/ library
Installing gems in a non-standard directory.
How do I install gems in a non-standard location, such as my home directory?
You have to redefine the location of the GEM_HOME variable and add the paths to the gem repositories in the RUBYLIB variable before launching the installation into a custom directory.
GEM_HOME should point to $PREFIX/lib/ruby/gems/1.8 if it used with the 1.8 version of ruby.
RUBYLIB should point to the $PREFIX/lib/ruby and $PREFIX/lib/site_ruby/1.8
Here is a shell script that runs in the rubygems
distribution directory to install into /home/user :
PREFIX=$HOME
export GEM_HOME=$PREFIX/lib/ruby/gems/1.8
export RUBYLIB=$PREFIX/lib/ruby:$PREFIX/lib/site_ruby/1.8
ruby setup.rb all --prefix=$PREFIX
You may add GEM_HOME and RUBYLIB into your ~/.profile file to automatically load on login.
Trouble Shooting Questions
I’m getting parse errors while installing a gem. What’s wrong?
After I updated RubyGems, I tried to install a gem and got parse errors:
[C:\]gem install rails
"c:\ruby\bin\ruby.exe" "c:\ruby\bin\gem" install rails
Attempting local installation of 'rails'
Local gem file not found: rails*.gem
Attempting remote installation of 'rails'
ERROR: While executing gem ... (ArgumentError)
parse error on line 2, col 92:
`@gems{???"?rwdtinker-1.60o:?Gem::Specification:?@email"?steven@superant.com:?@requirements['
Any idea what’s going on? Can I roll back to the
rubygems version I had before?
Answer
It sounds like your source cache is either corrupted or not in the format expected. Around version 0.8.5 or so we switched from a YAML based cache to a marshalled cache (with a significant increase in speed). If you run a 0.8.5 or later version of gems and then later try to go back to a pre-0.8.5 version, the earlier version is confused by the data in the cache (post 0.8.5 versions are smart enough to just toss the cache if it looks bad).
To fix, just delete the source cache file (the file named source_cache in the directory reported by the ‘gem env gempath’ command). If you are on a unix-like OS and the source_cache is in a protected directory, you might have
another copy of the source cache available in a user owned directory (probably $HOME/.gem/source_cache). Delete that copy as well.
RubyGems hangs while updating the source index.
I have a problem with RubyGems. It doesn’t matter what I try to install with, it freezez.
Particulary I tried to execute:
gem install rails --include-dependencies
but the command freezez at the following message:
"Updating Gem source index for: http://gems.rubyforge.org"
Answer
[I lost my internet connection while composing the answer to this question. Unfortunately, I now no longer recall what I intended to write. The answer (or at least part of the answer) is buried deep in the RubyGems mail archive. I’ll try to update this after a bit of research. Sorry for leaving this question hanging.]
No such file to load—rubygems
When I run the gem command, I get the following error message:
ruby: No such file to load -- rubygems (LoadError)
What’s wrong?
Answer
It looks like executing copy of Ruby does not have the RubyGems library installed. RubyGems was probably installed at one time (because the gem command is recognized), but it may have been installed on a different installation of Ruby than the one you are currently running.
Things to check
- Check that the installation of Ruby that is running is the same one that has RubyGems installed. On a unix system, the which command (or type command) will help figure this out.
- Verify that the currently running installation of Ruby does indeed have the RubyGems library installed. You should find a “rubygems.rb” file in the site_ruby/1.8 directory of the Ruby installation.
These mixup can easily happen after installing a new instance of Ruby, but the old instance preceeds the new one in the PATH list.
Why does require return false when loading a file from a gem?
Require returns false when loading a file from a gem. Usually require will return true when it has loaded correctly. What’s wrong?
Answer
Nothing. Well, something. But nothing you need to worry about.
A false return from the require method does not indicate an error. It just means that the file has already been loaded.
RubyGems has a feature that allows a file to be automatically loaded when a gem is activated (i.e. selected). When you require a file that is in an inactive gem, the RubyGems software will activate that gem for you. During that activation, any autoloaded files will be loaded for you.
So, by the time your require statement actually does the work of loading the file, it has already been autoloaded via the gem activation, and therefore it returns false.
As we said, it is not a problem, but it sure is confusing to folks doing requires in an irb session. Future versions of RubyGems will correct this behavior.
Advanced Questions
How do I run my own gem server?
The simpliest way is to run the command:
gem_server
This will serve all your installed gems from your local machine. The URL for the server will be http://YOURHOSTNAME:8808. Use the --help option on gem_server for a complete list of options.
How do I run a gem server like rubyforge?
Don’t forget to check out the easy answer for running a simple gem server.
But is is also fairly easy to serve gems from static files on an existing web server. Here’s what you need to do.
- Create a directory in the public files area of your web server (we will call that directory BASEDIR in the following instructions).
- Create the subdirectory BASEDIR/
gems.
- Copy any gems you wish to serve into the BASEDIR/
gems subdirectory.
- Run the
generate_yaml_index.rb command (distributed with RubyGems) to generate the yaml and yaml.Z files needed by the RubyGems client. The command will look something like this:
generate_yaml_index.rb -d BASEDIR
That’s it. The URL for the server will be whatever URL references BASEDIR. Just rerun the generate_yaml_index.rb command whenever you add (or remove) gems from the server.
|