Rip: A New Way to Package Ruby Software

Tired of juggling Ruby gems? Try Rip. It's a one-size-fits-all, no fuss, powerful package manager.

For example, on the test machine, with Bash as the login shell, the file $HOME/.profile was amended to contain these lines.

# -- start rip config -- #
# -- end rip config -- #

RIPDIR sets the path to your Rip database. RUBYLIB is a colon-separated list of directories that are added to Ruby’s library load path. PATH is also a list of directories and is used to find executables. Rip combines these three as shown to find libraries to load and binaries to run from your active environment. (Remember, active is a symlink. Its target changes, but its name remains constant. Hence, these environment variables are much of the magic of Rip.)

If another user has already installed Rip on your system, you must (for now) manually configure Rip for your personal use. Create a directory for your Rip database and edit your shell startup file to set RIPDIR, RUBYLIB, and PATH. Be sure to set RIPDIR appropriately; you can use the latter two lines verbatim. Logout and login again or source the modified startup file to pick up the changes.

Once you start a new session, run rip check again and all should be well.

$ rip check
All systems go.

If you need assistance running Rip, type rip --help for a list of options.

$ rip --help
Usage: rip COMMAND [options]

Commands available:

For more information on a command use:
  rip help COMMAND

  -h, --help     show this help message and exit
  -v, --version  show the current version and exit

Managing Environments

To create a new environment, use the env command.

$ rip env create alpha
ripenv: created alpha
$ rip env create beta
ripenv: created beta

Whenever you create a new environment, it becomes active.

$ rip env active
ripenv: beta

You can change to another environment using env use.

$ rip env use base
ripenv: using base

You can also copy and delete an environment (rip env copy and rip env delete, respectively), query which environment is active (rip env active), and enumerate all available environments (rip env list). Copy and delete are cheap operations and combined are a great way to quickly test if a new package can be mixed among the existing contents of an environment. If something fails, just delete the broken environment and start over. Delete is also the fastest way to uninstall a large number of packages in one fell swoop.

By the way, you cannot (naturally) delete the active environment. You must activate another environment and then run delete.

$ rip env use beta
ripenv: using beta
$ rip env delete beta
ripenv: can’t delete active environment
$ rip env use base
ripenv: using base
$ rip env delete beta
ripenv: deleted beta

Installing Packages with Rip

As mentioned above, Rip can install Ruby code from four sources (with more to come): a directory, a single file, a Git repository, and a gem. Moreover, if the source of the code includes a special file named deps.rip in the root of the project, all sources named in that file are also installed. deps.rip isn’t required; but if it’s provided, the source is considered a proper Rip repository and its contents are treated as dependencies.

To demonstrate how Rip works, let’s install a package from a Git repository. Specifically, let’s install Grit, since it’s already a proper Rip package. Grit gives you object-oriented access to Git repositories via Ruby. This is Grit’s deps.rip:

git://github.com/halostatue/mime-types.git v1.16

To install Grit, run rip install git://github.com/defunkt/grit.git.

$ rip install git://github.com/defunkt/grit.git
running install hook for diff-lcs
Successfully installed diff-lcs (491fbc0)
running install hook for mime-types
Successfully installed mime-types (v1.16)
running install hook for grit
Successfully installed grit (e37664)

Here’s how rip install works:

  1. First, the latest code from the Grit GitHub repository is fetched and unpacked in the directory of the active environment.
  2. Next, the code for each dependency listed in deps.rip is fetched, unpacked, and installed in the directory associated with the current environment. Executables are placed in bin; code in lib.
  3. Recursively, the dependencies of each dependency are fetched, unpacked, and installed in the current environment.
  4. Finally, the package originally requested is installed into the active environment.

Steps 2-4 can apply to a directory, repository, or gem, if deps.rip exists. And in any case, if multiple versions of the same library are ever referenced as dependencies, the entire process halts with an error.

To install a file, just name the file. For instance, if the file object_mods.rb adds a handful of convenience functions to Object, you can install it in the current environment with rip install object_mods.rb.

$ rip install object_mods.rb
Successfully installed object_mods.rb (2009-06-16)

The operation copies the raw file to rip-packages for safekeeping and copies the file to active/lib in the Rip directory. The file can be local or on the Web. For the latter, simply provide the URL as the argument.

An individual file is versioned, too. If you edit object_mods.rb and try to install the new version into the current environment, Rip complains of a conflict.

$ vi object_mods.rb
... make some changes and save ...
$ rip install object_mods.rb
version conflict!
rip: installation failed

You can also install a directory with Rip. Just point to the directory and anything in subdirectory lib is copied to the current environment.

For example, assuming that ~/myapp is a Rails application, the command rip install ~/myapp copies the Ruby files found in ~/myapp/lib to the current environment.

$ rip install ~/myapp
unpacking myapp (unversioned)...
running install hook for myapp
Successfully installed myapp (unversioned)

You can also install a local copy of a gem from its directory. For instance, given a copy of Markaby in ~/src/Markaby, run the command rip install ~/src/Markaby to install Markaby into the current environment.

$ rip install ~/src/Markaby
unpacking markaby-0.5 (0.5)...
running install hook for markaby-0.5
Successfully installed markaby-0.5 (0.5)

You can also install a gem directly, assuming you have version 1.3.3 or later of the gem utility installed on your system. (Earlier versions of the gem utility cause this operation to fail.)

$ rip install tlsmail
Searching gems.github.com for tlsmail...
ERROR:  Could not find tlsmail in any repository
Searching gems.rubyforge.org for tlsmail...
running install hook for tlsmail
Successfully installed tlsmail (0.0.1)

Stupid Rip Tricks

Here are some other clever tricks for Rip.

  • You can create an ad hoc .rip file at any time to install a collection of libraries into an environment all at once. Of course, the dependencies for the collection and its target environment can’t conflict; otherwise, this is a convenient method to populate an environment suitable to run an existing project.
  • You can remove a single package from an environment with rip uninstall package. Add -d to remove the package and everything that depends on it.
  • If you use JRuby, you can run Ruby code with JRuby in the current environment. Just type jruby app.rb. Similarly, if you have have the Ruby 1.9 interpreter installed on your machine as ruby19, just type ruby19 app.rb to run that code in the active environment.
  • To run a daemon in the current environment, use rip ruby environment app.rb, where environment is the name of one of your environments. By default, rip ruby runs the interpreter named ruby. You can name a different interpreter with the RUBYBIN environment variable.

    For example, the command…

    $ RUBYBIN=jruby rip ruby beta app.rb

    … runs a daemon using JRuby in the beta environment.

Rip Rip Hooray!

Rip is brand new, so rough edges are to be expected. Still, its features are quite impressive and useful as-is and it can only get better. Try Rip out and follow its progress via the Rip Google Group. And happy tinkering!

Fatal error: Call to undefined function aa_author_bios() in /opt/apache/dms/b2b/linux-mag.com/site/www/htdocs/wp-content/themes/linuxmag/single.php on line 62