Javascript 在 Ubuntu 上获取蜘蛛猴 js 的最佳方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6656904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best way to get spidermonkey js on Ubuntu?
提问by ovrkenthousand
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:
我需要在我的工作机器上安装 Spidermonkey JS 引擎。我正在处理的项目有一个 jslint 脚本,需要 Spidermonkey 或类似的 js 二进制文件。我试过从源代码编译 Spidermonkey 并陷入依赖地狱。我尝试从 ubuntu 存储库安装 rhino 包,结果发现它很慢而且很坏。今天早上,我按照这里的说明成功编译了谷歌的 V8 引擎并构建了 v8jslint:
http://blog.stevenreid.co.uk/2011/06/27/jslint-command-line-tool-powered-by-v8/
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 可以工作,但一次只能 lint 一个文件。例如,
$ 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?
如果我在 foo 下有 a.js、b.js 和 c.js,v8jslint 只会对 a.js 进行 lint。简单修复:我可以为此编写一个 bash 脚本。一个更大的问题是 v8jslint 与我们构建服务器上的 Spidermonkey jslint 不兼容。有没有人在最新版本的 Ubuntu 上成功构建 Spidermonkey,或者知道一个好的解决方法?
回答by easel
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:
您可以从源代码构建,但蜘蛛猴在 ubuntu 上仍然可用,它只是被重命名为 "libmozjs"。安装“libmozjs-24-bin”,然后将其称为“js24”或将 /usr/bin/js24 符号链接到“js”,如下所示:
sudo apt-get install libmozjs-24-bin; sudo ln -sf /usr/bin/js24 /usr/bin/js
回答by ovrkenthousand
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.
修复。您需要“autoconf2.13”包。使用 apt-get 安装它。转到 Mozilla 上的 SpiderMonkey 源代码页面。找到 hg 存储库(链接如下)并下载 Mozilla 树的快照。不要克隆它,只需从顶部栏中获取存档为 .tar.gz 或 .tar.bz2。
http://hg.mozilla.org/index.cgi/mozilla-central/file/tip
http://hg.mozilla.org/index.cgi/mozilla-central/file/tip
Unzip the archive and cd into the root directory.
将存档和 cd 解压缩到根目录中。
$ 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
这应该生成一个名为 js 的二进制文件。出于某种原因,当我运行 make install 时,它没有将 js 复制到 /bin/ 中。我只是符号链接 /bin/js 指向 ~/.../mozilla/js/src/js。Lint 脚本现在可以工作了,我不再需要开始构建来修复 lint 错误:P
Source:
来源:
https://developer.mozilla.org/en/SpiderMonkey_Build_Documentation
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.
注意:上面的链接调用命令autoconf-2.13
。我认为这是一个错字;你想像autoconf2.13
我在代码中写的那样使用。
回答by scytale
update:
更新:
looks like spidermonkey-bin is no longer available through the launchpad ppa
看起来 Spidermonkey-bin 不再通过启动板 ppa 可用
plus the v8jslint repo was down when I tried to clone it.
加上当我尝试克隆它时 v8jslint 存储库已关闭。
回答by sdaau
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:
此外,(通过#2:spidermonkey-bin 在 Ubuntu Lucid 中不可用 - 问题 -hallettj/jslint.vim - GitHub),可以使用PPA 进行 Launchpad 工程:“Canonical Launchpad Engineering”团队:
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
$
回答by thrau
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
.
安装软件包libmozjs-24-bin
。它包含 Spidermonkey JavaScript shell 二进制文件/usr/bin/js24
,您可以将其安装为命令的替代js
。
sudo apt-get install libmozjs-24-bin
sudo update-alternatives --install /usr/bin/js js /usr/bin/js24 10