Naked JavaScript

Taking the DOM off JavaScript 
« Back to blog

Installing v8 on Mac OS X and Linux

Google's v8 JavaScript Interpreter made a huge splash and to many was the indication of the browser war of the modern era. The effects of Google's entrance into the browser world are not yet fully known and expands with nearly every action by Google. V8 is written in C++ and is the fundamental differentiator of Google Chrome from Apple's Safari web browser. When v8 came out it nearly doubled the speed of the competition, all of which have returned to the neck and neck speed levels. Google has made a strong bet on JavaScript as a fundamental factor for the future of not only the web, but their company as a whole with the announcement of a "Web OS" in Google Chrome OS. In terms of disruptive technologies that have long reaching ramifications, there is a general consensus within the JavaScript community that v8 is a prime leader for both client side AND server side JavaScript.

Installing v8 is relatively trivial thanks to its main dependency, the SCons build system. SCons is a build system built in Python and designed around more modern programming systems. Its a great improvement over previous build systems like make, but we are not going to get crafty about the install of SCons at this point because we have already relied on the available package managers for each system. You will also need Subversion installed in order to checkout the latest version of v8. If you already have installed Subversion prior to this article, then just exclude "subversion" from the following command.

To install SCons and Subversion on Mac OS X, issue the following command:

sudo port install scons subversion

To install SCons and Subversion on Linux, issue the following command:

sudo apt-get install zip scons subversion

Note: If you are running Linux in a x64 environment, you will have to ensure that you install the multilib packages using the following command, which if you want you can append the packages to the end of the previous command:

sudo apt-get install g++-multilib gcc-multilib

If you are asked about dependencies during this install process, you can positively accept them as they will be necessary for full functionality. 

Once you have all of the necessary dependencies installed, be sure you are in the "javascript" directory we created in the Getting Started process. Issue the following commands while in that directory in order to download and build the v8 engine (vroom, vroom), these commands work regardless of your operating system,

Notice the sample=shell, this is what tells the SCons build system to configure and compile V8 with an executable shell or Read-Eval-Print-Loop (REPL) script so that we can play with as easily as we have the other JavaScript engines. This process will take a fairly long time, as you have most likely come to expect in building the previous JavaScript interpreters. Once it is complete, you will have a new file located in that directory called shell that is by default executable. Since "shell" is not very specific to what we are doing I recommend that you symbolically link this file into a path accessible directory. If you have /usr/local/bin available in your path it is a simple as the executing the following command in the terminal:

sudo ln -s ~/javascript/v8/shell /usr/local/bin/v8

This will create a symbolic link of v8 to the shell command so that you will only need to type "v8" in the terminal and it will begin execution. This works quite well especially when you update the code, which can be done in the following way:

Now we have the last of our JavaScript interpreters installed and ready, we can now being to learn the ways of Naked JavaScript.

Loading mentions Retweet

Comments (4)

Aug 13, 2009
Joran Greef said...
Thanks Chris, this is great. I read your earlier posts and decided to try V8 before this post. I don't yet know C++ however. I've read the embedding articles re: exposing C++ libraries but am not much further. Being able to script C++ from within Javascript in the same way that one can script Java from within Rhino, would be great.
Aug 13, 2009
Chris Williams said...
That is in the queue for later in the series. 

Chris Williams
Sep 03, 2009
viren said...
Great article man but how do run it cuz for me plain v8 in terminal not working
Nov 30, 2009
2dc said...
It works perfectly!
Thanks for your great articles.

Leave a comment...

 
Got an account with one of these? Login here, or just enter your comment below.