To explain how this technique is applied, let's remind ourselves of Acme's setup. They have a production machine to which their applications are deployed, which contains most of the gems required by the developers (see, Chapter 3). Note that I said most, as Capistrano is not installed: technically, it is only required on the developer machines. However, to be able to serve it from the production machine, it needs to be installed on that machine too. (The gem_server
command only offers up gems installed on the machine where it is running.) They install Capistrano (and its dependencies) with the following:
$ gem install capistrano -y
Next, they can make the gems on the production machine available via HTTP using this simple command:
$ gem_server [2007-07-03 21:34:38] INFO WEBrick 1.3.1 [2007-07-03 21:34:38] INFO ruby 1.8.4 (2005-12-24) [i486-linux] [2007-07-03 21:34:38] INFO WEBrick::HTTPServer#start: pid=7543 port=8808
As you can see from the output, this starts a WEBrick server on the default port 8808 (gem_server -p N
can be used to start the server on port N
). Browsing to http://<server address>:8808/
(replacing <server address>
with the IP address or domain name of the production machine) will now yield the documentation for the gems on the server. We had a brief look at this feature in the section: A Note on Rails Documentation in Chapter 3. If the gems were installed without documentation (using the --no-rdoc
switch), you will just get a list of the installed gems without documentation links.
But there is another hidden aspect to the gem server: if you browse to the same address with the path /gems/
, i.e. to http://<server address>:8808/gems/
, you'll see the gems installed on the server displayed as links.
This indicates that the gem server is presenting its installed gems over HTTP. Once this is up and running, you can now use the gem
command line tool on a developer machine to list the gems on the gem server:
$ gem list --remote --source http://192.168.13.131:8808 Bulk updating Gem source index for: http://192.168.13.131:8808 *** REMOTE GEMS *** actionmailer (1.3.3) Service layer for easy email delivery and testing. ... etc. ...
(Replacing the IP address of the --source
URL with the one for your server, of course.)
You can also install a gem from your own gem server with:
$ sudo gem install rails -y --source http://192.168.13.131:8808 Password: Bulk updating Gem source index for: http://192.168.13.131:8808 Successfully installed rails-1.2.3
If you want to configure gem to use your gem server as the default repository, create a file called .gemrc
in your home directory (/home/username
on Linux, Documents and Settings\Username
on Windows). Next, add this single line (it's a YAML file):
gem: --source http://192.168.13.131:8808 -y
Remember to replace the --source
URL with the one appropriate to your server. Note that I also added the -y
switch to ensure that all dependencies are installed each time you install a gem. Now, each time you install a gem, your intranet gem server will be used as the default repository, rather than the public Internet gem repository.