4

How to install and configure Mozilla SpiderMonkey js engine in Ubuntu Server 16.04? I want to use SpiderMonkey to run JavaScript code in my web app.

0
4

SpiderMonkey is the code-name for the Mozilla's C++ implementation of JavaScript. It is intended to be embedded in other applications that provide host environments for JavaScript.


Ubuntu 21.04-22.04

To install SpiderMonkey in Ubuntu 21.04 and later open the terminal and type:

sudo apt install libmozjs-78-0 libmozjs-78-dev  

To start Mozilla's SpiderMonkey engine, which can also be used as an interactive interpreter, from the terminal type:

js78

Ubuntu 20.04-20.10

To install SpiderMonkey in Ubuntu 18.04-20.04 open the terminal and type:

sudo apt install libmozjs-68-0 libmozjs-68-dev  

To start Mozilla's SpiderMonkey engine, which can also be used as an interactive interpreter, from the terminal type:

js68  

To exit from js68:

quit() 

Ubuntu 18.04-20.10

To install SpiderMonkey in Ubuntu 18.04-20.04 open the terminal and type:

sudo apt install libmozjs-52-0 libmozjs-52-dev  

To start Mozilla's SpiderMonkey engine, which can also be used as an interactive interpreter, from the terminal type:

js52  

To exit from js52:

quit() 

Ubuntu 16.04-17.10

To install SpiderMonkey in Ubuntu 16.04-17.10 open the terminal and type:

sudo apt install libmozjs-24-0v5 libmozjs-24-bin  

To start Mozilla's SpiderMonkey engine, which can also be used as an interactive interpreter, from the terminal type:

js24  

To exit from js24:

quit()  

For additional information about how to execute JavaScript without a web browser see: Executing JavaScript without a browser?. In particular I recommend that you run the foo.js example code at the end of rbrito's answer.

My example code:

#!/usr/bin/js
var animal = "dog";
var count = 2;
console.log("The", animal, "ate", count, "biscuits.");

Results:

The dog ate 2 biscuits.
6
  • Is 24 referring to a version, will this increase in the future? Mar 15 '17 at 7:53
  • Yes, it's referring to Firefox 24 and later. I don't know if Mozilla plans to update the version of SpiderMonkey, but I guess the version will be updated eventually, when I don't know.
    – karel
    Mar 15 '17 at 11:35
  • Why does it stop at 52? Jul 17 '20 at 18:36
  • @MinhNghĩa It doesn't stop at 52. Ubuntu 20.04 and later has libmozjs-68-0 and libmozjs-68-dev, as well as libmozjs-52-0 and libmozjs-52-dev.
    – karel
    Jul 17 '20 at 21:31
  • @karel Figured it out :) However, I'm still confused: FF is now at 78, why is SpiderMonkey stuck at 68? Is it related to ESR2, which is 68 now? Jul 17 '20 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.