# Gem installer and scripts

**URL:** <https://www.ruby-forum.com/t/gem-installer-and-scripts/69579>\
**Category:** Ruby\
**Created:** [September 21, 2006, 11:34pm UTC](https://www.ruby-forum.com/t/gem-installer-and-scripts/69579 "2006-09-21T23:34:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tedx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9fc29f/32.png) [@tedx](https://www.ruby-forum.com/u/tedx)\
**Post date:** [September 21, 2006, 11:34pm UTC](https://www.ruby-forum.com/t/gem-installer-and-scripts/69579/1 "2006-09-21T23:34:28Z")

</div>

Is there a way to get gem to run a script during an install similar to  
rpms pre/post-install? How do others deal with needing to copy files or  
create links etc. during a gem install?

Ted

---

<div class="post-metadata">

**Author:** ![tedx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9fc29f/32.png) [@tedx](https://www.ruby-forum.com/u/tedx)\
**Post date:** [September 21, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/gem-installer-and-scripts/69579/2 "2006-09-21T23:55:33Z")

</div>

On 9/21/06, Ted T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there a way to get gem to run a script during an install similar to  
> rpms pre/post-install? How do others deal with needing to copy files or  
> create links etc. during a gem install?

Include a script with one of the following names in the base directory  
of your gem:  
install.rb  
post-install.rb  
uninstall.rb

They get run pretty much when the names suggest. See gems like  
activerecord, rake, and rmagick for examples.

---

<div class="post-metadata">

**Author:** ![tedx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9fc29f/32.png) [@tedx](https://www.ruby-forum.com/u/tedx)\
**Post date:** [September 22, 2006, 3:32pm UTC](https://www.ruby-forum.com/t/gem-installer-and-scripts/69579/3 "2006-09-22T15:32:14Z")

</div>

Wilson B. wrote:

> On 9/21/06, Ted T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Is there a way to get gem to run a script during an install similar to  
> > rpms pre/post-install? How do others deal with needing to copy files or  
> > create links etc. during a gem install?
> 
> Include a script with one of the following names in the base directory  
> of your gem:  
> install.rb  
> post-install.rb  
> uninstall.rb
> 
> They get run pretty much when the names suggest. See gems like  
> activerecord, rake, and rmagick for examples.

Thanks. I created a post-install.rb and tested it but it doesn’t get run  
during the install as best I can tell. I’ve looked at the gem code and I  
don’t see code that would run my post-install.rb script maybe I just  
missed it but … Would you know where this happens? I did look at gems  
already on my system but they only contain install.rb files.

---

<div class="post-metadata">

**Author:** ![tedx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9fc29f/32.png) [@tedx](https://www.ruby-forum.com/u/tedx)\
**Post date:** [September 22, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/gem-installer-and-scripts/69579/4 "2006-09-22T23:54:36Z")

</div>

Ted T. wrote:

> > of your gem:  
> > don’t see code that would run my post-install.rb script maybe I just  
> > missed it but … Would you know where this happens? I did look at gems  
> > already on my system but they only contain install.rb files.

I can only speak for RMagick, but fwiw,

install.rb was Minero A.'s generic Ruby library/application installer  
script, which predates RubyGems. I’ve since replaced it in the RMagick  
install with Minero’s setup.rb  
([setup.rb](http://i.loveruby.net/en/projects/setup/)). (This is the same setup.rb  
that you run to install RubyGems the first time.) The  
install.rb/setup.rb scheme defines three steps during installation:  
config, setup, and install. Each specific application/library can define  
“hooks” that run before or after each step. A “hook” is a Ruby program.  
The hook scripts are identified by their name, which is “pre-” or  
“post-” followed by the step name. Thus “post-install.rb” is a hook that  
runs after the install step. Therefore setup.rb runs the RMagick  
post-install.rb hook after it completes the standard installation tasks.  
In the RMagick case, post-install.rb copies the RMagick documentation  
files to the doc directory. The install.rb/setup.rb process doesn’t  
define an uninstall step, so for RMagick, I provided a uninstall.rb  
script that can be executed for the “make uninstall” target, or simply  
by running “ruby uninstall.rb” from the command line.

Probably RMagick isn’t a good model for an installation process. RMagick  
was out there before there was a RubyGems, so I created an installation  
process based on the at-the-time-standard install.rb/setup.rb code.  
Later, at the request of an important but traditionally-minded supporter  
I hacked a GNU configure/make/make install over that, and when RubyGems  
came out I hacked it to work with RubyGems. I’m sure Rake and  
activerecord are much better models.

The last time I checked RubyGems, for security purposes, did not support  
the execution of arbitrary user-supplied scripts. Remember RubyGems may  
be running with root/admin priviledges, so it wouldn’t be wise to allow  
just any ol’ Ruby library developer to add code to the installation  
process. To the best of my knowledge, if you can’t specify it in a  
gemfile you can’t make RubyGems do it. If I’m wrong I’m sure somebody  
will correct me.
