ovrkenthousand
ovrkenthousand

Reputation: 478

Best way to get spidermonkey js on Ubuntu?

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?

Upvotes: 16

Views: 24889

Answers (5)

easel
easel

Reputation: 4048

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

Upvotes: 22

thrau
thrau

Reputation: 3100

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

Upvotes: 3

scytale
scytale

Reputation: 12641

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.

Upvotes: 6

sdaau
sdaau

Reputation: 38619

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
$

Upvotes: 5

ovrkenthousand
ovrkenthousand

Reputation: 478

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.

Upvotes: 16

Related Questions