I would like to run ruby programs from anywhere. I think I have understood it is RUBYLIB. But I can't make it work. Could you give examples ?
Asked
Active
Viewed 5,459 times
6
-
2To the none-java people that are rubyists: What is the CLASSPATH in java? :) – August Lilleaas Sep 25 '09 at 10:21
-
CLASSPATH is the ; or : separated list of directories containing *.class files or libraries (containing *.class files) for the Java VM to resolve dependencies when a class is loaded. – Peter Kofler Sep 25 '09 at 11:47
-
I take the question to mean that in Java there are a set of annoying classpath "issues." What corresponds to classpath problems in Ruby? Missing gems/what? still not really answered well, IMHO. – Thufir Mar 30 '12 at 16:06
2 Answers
5
- You need to manupulate the load path
$LOAD_PATH ($:)
- This is done with
-I directories
(Directories are separated by a:
on Unix-like systems and by a;
on DOS/Windows systems.) - You could add
-I
switches toRUBYOPT
($SAFE
must be 0) - Or with
RUBYLIB
($SAFE
must be 0 also) which contains search paths. RUBYPATH
also changes search path for Ruby programs.- For environment variables, make sure they are proper set or exported so the Ruby VM sees them. You could add a debug print in the ruby.bat or ruby.sh.
- Check your
$SAFE
setting. If you don't know about it, then its probably fine.
I allways set RUBYLIB
and RUBYPATH
to my loadpath and add the -S
option to the interpreter call.

Peter Kofler
- 9,252
- 8
- 51
- 79
1
There is an option -S which looks for the script using PATH environment variable.
for example doing:
ruby -S some_script
Will look for the some_script in current operating system PATH environment variable.
Update: If your script requires other files then use the following statement:
require File.join(File.dirname(__FILE__), "name_of_required_file")
instead of:
require "name_of_required_path"

khelll
- 23,590
- 15
- 91
- 109
-
Ok, the aforementioned file "some_script" is now correctly found by ruby (thx!), but this file also contains a 'require 'foo'", that is not loaded (LoadError). It resides in the same directory as the first script... Any idea ? – JCLL Sep 25 '09 at 16:19
-
1To get your required file included you can do the following require File.join(File.dirname(__FILE__), "name_of_required_file") – Steve Weet Sep 25 '09 at 18:04
-
The comment code remove 2 underscores before and after the file it should be xxFILExx where x is an underscore – Steve Weet Sep 25 '09 at 18:04
-