# Shared scripts and ruby gems

**URL:** <https://www.ruby-forum.com/t/shared-scripts-and-ruby-gems/112282>\
**Category:** Ruby\
**Created:** [August 17, 2007, 1:27am UTC](https://www.ruby-forum.com/t/shared-scripts-and-ruby-gems/112282 "2007-08-17T01:27:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Schidlowsky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@Michael\_Schidlowsky](https://www.ruby-forum.com/u/Michael_Schidlowsky)\
**Post date:** [August 17, 2007, 1:27am UTC](https://www.ruby-forum.com/t/shared-scripts-and-ruby-gems/112282/1 "2007-08-17T01:27:35Z")

</div>

Hello everyone,

If I’m writing a ruby script that uses a certain library (e.g.  
Chronic) and I want to share that script with other users by making it  
publicly executable on a linux filesystem, do I need to do anything in  
the script to make sure that the gem is installed or will other users  
just end up using my copy of the gem automatically (in which case it’s  
enough for me to just run “gem install chronic”)?

Thanks!  
-Michael

---

<div class="post-metadata">

**Author:** ![Michael\_Schidlowsky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@Michael\_Schidlowsky](https://www.ruby-forum.com/u/Michael_Schidlowsky)\
**Post date:** [August 17, 2007, 4:04am UTC](https://www.ruby-forum.com/t/shared-scripts-and-ruby-gems/112282/2 "2007-08-17T04:04:38Z")

</div>

Michael Schidlowsky wrote:

> Hello everyone,
> 
> If I’m writing a ruby script that uses a certain library (e.g.  
> Chronic) and I want to share that script with other users by making it  
> publicly executable on a linux filesystem, do I need to do anything in  
> the script to make sure that the gem is installed or will other users  
> just end up using my copy of the gem automatically (in which case it’s  
> enough for me to just run “gem install chronic”)?
> 
> Thanks!  
> -Michael

so long as you include the library / gem in ur script then so long as  
they have that library / gem installed, they shouldnt have a problem, if  
they dont have it installed then the program simply wont run…if the  
user of the script has any idea of how the script works they should be  
able to easily look at the top few lines to ensure they have the proper  
libraries and/or gems installed.

require ‘gem\_name\_or\_library’

### 

if they dont have it installed, they will get a LoadError…

on the flipside if u wanted to “check” if they have it installed just  
use a  
raise LoadError approach

---

<div class="post-metadata">

**Author:** ![Michael\_Schidlowsky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@Michael\_Schidlowsky](https://www.ruby-forum.com/u/Michael_Schidlowsky)\
**Post date:** [August 17, 2007, 5:12pm UTC](https://www.ruby-forum.com/t/shared-scripts-and-ruby-gems/112282/3 "2007-08-17T17:12:04Z")

</div>

Michael,

Thanks for the response. Do you know if there’s any way I can package  
up the gem with my script somehow (like include it in a subdirectory  
of the script location and load it from there) so that I can guarantee  
the library is there even if the user does not have it installed?

Thanks,  
Michael

---

<div class="post-metadata">

**Author:** ![Michael\_Schidlowsky](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@Michael\_Schidlowsky](https://www.ruby-forum.com/u/Michael_Schidlowsky)\
**Post date:** [August 21, 2007, 2:00am UTC](https://www.ruby-forum.com/t/shared-scripts-and-ruby-gems/112282/4 "2007-08-21T02:00:34Z")

</div>

Michael Schidlowsky wrote:

> Do you know if there’s any way I can package  
> up the gem with my script somehow (like include it in a subdirectory  
> of the script location and load it from there) so that I can guarantee  
> the library is there even if the user does not have it installed?

Add the path of the embedded gem’s lib/ directory to the $: array (if  
you’re in Ruby) or the RUBYLIB environment variable (if you’re in a  
shell script).
