Compiling the V8 JavaScript runtime under 64-bit Ubuntu

File under “I’m writing this for the benefit of my future self, and may not work on your machine.” I recently upgraded my home machine to a 64-bit edition of Ubuntu 10.04 and had do to more than the usual dance to get Google’s blazing fast V8 JavaScript interpreter to compile. Here’s what I did.

First up, install the usual build tools you’d need to compile V8:

sudo aptitude install build-essential subversion scons

Then, as detailed on the Chromium bug tracker, install a bunch of support libraries:

sudo aptitude install ia32-libs lib32z1-dev lib32bz2-dev

You will also find that the build complains about the absence of something called lstdc++ unless you do the following (replace 6.0.13 with whatever the version installed on your machine is):

sudo ln -s /usr/lib32/libstdc++.so.6.0.13 /usr/lib32/libstdc++.so

Finally, you can check out V8:

cd /usr/src
sudo svn checkout http://v8.googlecode.com/svn/trunk/ v8
cd v8

You’ll then need to stop the build being quite so whiny by editing v8/SConstruct as follows. Find the part of the file that looks roughly like this:

V8_EXTRA_FLAGS = {
  'gcc': {
    'all': {
      'WARNINGFLAGS': ['-Wall',
                       '-Werror',
                       '-W',
                       '-Wno-unused-parameter',
                       '-Wnon-virtual-dtor']

and comment out the '-Werror' line by placing a # at the beginning of it. Now, you should be ready to build:

sudo scons sample=shell
sudo ln -s /usr/src/v8/shell /usr/bin/v8

You should now be able to use V8 to run any JavaScript file you like. Failing that, just go and install Node, it’s much easier.