Installing Rhino on Mac OS X or Linux
Rhino from Mozilla is entirely written in Java, which has made it an ideal platform for JavaScript development of many server and client side applications. By being built in Java, Rhino actually has access to every built-in function and library within the Java ecosystem. This is a huge benefit especially for people that are familiar with Java development or are looking to integrate JavaScript into an existing project. In contrast to the other engines we will be installing, installing and using Rhino is relativlely trivial.
To begin, you will need the Java SDK installed. For Mac OS X this is installed by default, but for versions of Linux this may not be the case. If you are running Linux, issue the following command to ensure that you have a proper installation of the Java runtime.
which java
If this returns nothing, it will mean that you have to install Java on your Linux computer. For Debian/Ubuntu versions of Linux you simply need to enter the following command:
sudo apt-get install sun-java6-bin sun-java6-jre
For directions on how to accomplish this with other versions of Linux, review this wikihow article.
Once you have verified and, if necessary, installed Java, you are ready to being the process of obtaining Rhino. While in the aforementioned "javascript" directory issue the following commands to obtain and unpack the Rhino package.
At this point, you have everything you need to execute a working, DOM-less JavaScript environment. While you are in the "rhino1_7R2" directory, enter the following command into the terminal in order to start your first JavaScript REPL (Read-Eval-Print-Loop) shell:
java -jar js.jar
You should see a prompt that is similar to the below
Rhino 1.7 release 2 2009 03 22
js>
At this point you have a working and fully functional JavaScript shell, to verify this you can do the proverbial verification test:
print("Hello New World");
Which will of course output "Hello New World" and provide you with a new prompt "js>" and with little effort you have installed your first JavaScrpt engine and executed your first bit of Naked JavaScript.
NOTE: To quit the shell, simply type
quit()
if you type just "quit" without the parenthesis, you will be returning the function to the printer instead of executing the function. It will look something like this:
function quit() { [native code, arity=1] }
This is actually the first peek into the functional programming side of JavaScript. As you can see it is the actual function definition, which uses native code to stop the executing shell. If this was a user-space function, you would actually see the full function definition, but more on these sorts of things later.