16

I need to install the Spidermonkey JS engine on my work machine. The project I'm working on has a jslint script that requires Spidermonkey or a similar js binary. I've tried compiling Spidermonkey from source and gotten stuck in dependency hell. I tried installing the rhino package from the ubuntu repositories, and that turned out to be slow and broken. This morning, I successfully compiled Google's V8 engine and built v8jslint following the instructions here:

http://blog.stevenreid.co.uk/2011/06/27/jslint-command-line-tool-powered-by-v8/

v8jslint works, but will only lint one file at a time. For instance,

$ v8jslint foo/*.js

if I have a.js, b.js and c.js under foo, v8jslint will only lint a.js. Easy fix: I could write a bash script for this. A bigger problem is that v8jslint is not compatible with the Spidermonkey jslint on our build server. Has anyone had any success building Spidermonkey on a recent version of Ubuntu, or know a good workaround?

Frew Schmidt
  • 9,364
  • 16
  • 64
  • 86
ovrkenthousand
  • 478
  • 1
  • 4
  • 9
  • Can I ask what you mean by "v8jslint is not compatible with the Spidermonkey jslint" please?. – Steve Jul 21 '11 at 06:45
  • "v8jslint is not compatible with the Spidermonkey jslint on our build server." That is, Spidermonkey's lint will catch certain errors that v8 misses and vice versa. So I don't know if the build will pass if I have v8 and the server runs spidermonkey. – ovrkenthousand Aug 12 '11 at 23:41

5 Answers5

22

You can build from source, but spider monkey is still available on ubuntu, it's just been renamed to "libmozjs". Install "libmozjs-24-bin" and then either refer to it as "js24" or symlink /usr/bin/js24 to "js", like so:

sudo apt-get install libmozjs-24-bin; sudo ln -sf /usr/bin/js24 /usr/bin/js
iFreilicht
  • 13,271
  • 9
  • 43
  • 74
easel
  • 3,982
  • 26
  • 28
16

Fixed it. You need the 'autoconf2.13' package. Install it with apt-get. Go to the SpiderMonkey source code page on Mozilla. Find the hg repository (linked below) and download a snapshot of the Mozilla tree. Don't clone it, just get the archive as .tar.gz or .tar.bz2 from the top bar.

http://hg.mozilla.org/index.cgi/mozilla-central/file/tip

Unzip the archive and cd into the root directory.

$ cd js/src
$ autoconf2.13
$ ./configure
$ make

This should make a binary called js. For some reason, when I ran make install, it did not copy js into /bin/. I just symlinked /bin/js to point to ~/.../mozilla/js/src/js. Lint scripts work now and I don't have to start a build to fix lint errors anymore :P

Source:

https://developer.mozilla.org/en/SpiderMonkey_Build_Documentation

Note: the above link calls for the command autoconf-2.13. I think this is a typo; you want to use autoconf2.13 as I wrote in the code.

ovrkenthousand
  • 478
  • 1
  • 4
  • 9
  • It's not a typo, on ArchLinux it's indeed called `autoconf-2.13`. It depends on your distro, I guess. – Rob W Feb 14 '13 at 11:07
6

update:

looks like spidermonkey-bin is no longer available through the launchpad ppa

plus the v8jslint repo was down when I tried to clone it.

scytale
  • 12,346
  • 3
  • 32
  • 46
5

Also, (via #2: spidermonkey-bin not availble in Ubuntu Lucid - Issues - hallettj/jslint.vim - GitHub), can use PPA for Launchpad Engineering : “Canonical Launchpad Engineering” team:

sudo add-apt-repository ppa:launchpad/ppa
sudo apt-get update
sudo apt-get install spidermonkey-bin
apt-cache show spidermonkey-bin
sudo apt-get install spidermonkey-bin # also installs extra: libmozjs2d

# .. and then: 
$ js --help
JavaScript-C 1.8.0 pre-release 1 2007-10-03
usage: js [-zKPswWxCij] [-t timeoutSeconds] [-c stackchunksize] [-o option] [-v version] [-f scriptfile] [-e script] [-S maxstacksize] [scriptfile] [scriptarg...]
$ js
js> var f = function(){ print("the answer is " + 42); }; 
js> f();
the answer is 42
js> ^C
$
sdaau
  • 36,975
  • 46
  • 198
  • 278
3

Install the package libmozjs-24-bin. It contains the Spidermonkey JavaScript shell binary /usr/bin/js24 which you can the be installed as an alternative for the command js.

sudo apt-get install libmozjs-24-bin
sudo update-alternatives --install /usr/bin/js js /usr/bin/js24 10
thrau
  • 2,915
  • 3
  • 25
  • 32