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 ?
To check our CLASSPATH on Windows we can open a command prompt and type echo %CLASSPATH%. To check it on a Mac you need to open a terminal and type echo $CLASSPATH.
The main difference between PATH and CLASSPATH is that Path is set for java tools in java programs like java and javac, which are used to compile your code. Whereas CLASSPATH is used by System or Application class loader to locate and load compile Java bytecodes stored in the . class file.
Setting the CLASSPATH can be tricky and should be performed with care. The default value of the class path is ".", meaning that only the current directory is searched. Specifying either the CLASSPATH variable or the -cp command line switch overrides this value.
CLASSPATH describes the location where all the required files are available which are used in the application. Java Compiler and JVM (Java Virtual Machine) use CLASSPATH to locate the required files.
$LOAD_PATH ($:)
-I directories
(Directories are separated by a :
on Unix-like systems and by a ;
on DOS/Windows systems.)-I
switches to RUBYOPT
($SAFE
must be 0)RUBYLIB
($SAFE
must be 0 also) which contains search paths.RUBYPATH
also changes search path for Ruby programs.$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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With