How to install and configure Mozilla SpiderMonkey js engine in Ubuntu Server 16.04
Solution 1:
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.