我如何设置&在 Ubuntu 上运行 PhantomJS?
我设置了 PhantomJS 并将其录制到视频中: https://www.dailymotion.com/video/xnizmh_1_webcam
构建说明: http://phantomjs.org/build.html
有什么吗我的设置有问题吗?
设置完成后,我阅读了 快速入门教程 并尝试编写此代码
phantomjs hello.js
它给我“找不到命令”错误。我该如何解决这个问题?
I set up PhantomJS and recorded it to video: https://www.dailymotion.com/video/xnizmh_1_webcam
Build instructions: http://phantomjs.org/build.html
Is there anything wrong in my setup?
After I set it up I read the quick start tutorial and tried to write this code
phantomjs hello.js
It gives me "command not found" error. How can I solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(25)
吉杜伊的回答让我走上了正轨。我必须向 /usr/bin/ 添加一个额外的符号链接,并且我为所有 3 个符号链接做了直接符号链接 - 见下文。
我正在 Ubuntu 服务器 Natty Narwhal 上安装。
这正是我所做的。
最后,当我这样做时,
我得到 1.9.7
如果有人发现我所做的有任何问题,请告诉我。
Guidouil's answer put me on the right track. I had to add one additional symlink to /usr/bin/, and I did direct symlinks for all 3 - see below.
I'm installing on Ubuntu server Natty Narwhal.
This is exactly what I did.
And finally when I do
I get 1.9.7
If anyone sees any problems with what I've done, please let me know.
PhantomJS 位于 npm 上。您可以运行此命令来全局安装它:
phantomjs -v
应返回2.1.1
PhantomJS is on npm. You can run this command to install it globally:
phantomjs -v
should return2.1.1
从 phantomjs 网站下载预构建包:
http://phantomjs.org/download.html
然后打开终端并转到下载文件夹,
然后检查安装
phantomjs -v
是否应返回1.8.1
download from phantomjs website the prebuilt package :
http://phantomjs.org/download.html
then open a terminal and go to the Downloads folder
then to check install
phantomjs -v
should return1.8.1
从包管理器安装:
Install from package manager:
以下是我使用的构建步骤(请注意,这些说明适用于版本 1.3。有关最新 PhantomJS 的安装说明,请参阅对此答案的评论):
现在安装 Xvfb
启动 Xvfb:
Xvfb :23 -screen 0 1024x768x24 &
现在运行 phantom:
DISPLAY=:23 ./phantomjs hello.js
Here are the build steps I used (note these instructions are for version 1.3. See comments to this answer for the installation instructions of the latest PhantomJS):
Now install Xvfb
Launch Xvfb:
Xvfb :23 -screen 0 1024x768x24 &
Now run phantom:
DISPLAY=:23 ./phantomjs hello.js
对于 1.5 以上的 PhantomJS 版本,请考虑以下内容(phantom 网站上构建说明的逐字副本):
For PhantomJS version above 1.5, consider this (verbatim copy of the build instructions on the phantom website):
对于 Ubuntu,您可以使用预构建版本可从 PhantomJS 站点下载。
如果您有闲暇时间,也可以自己构建。 (这正是 Nikhil 的回答中的过程)。
PhantomJS 的人建议使用二进制文件来节省时间:
对于现代机器来说,他们的意思是> 4 核,>我认为是 8GB 内存。我在一个微型 AWS 实例上尝试过,2 小时后放弃了。
简而言之:按照 PhantomJS 站点的说明安装预构建的软件包。
For Ubuntu you can use the prebuilt versions downloadable from the PhantomJS site.
If you have some serious time on your hands you can also build it yourself. (This is exactly the procedure from Nikhil's answer).
The guys over at PhantomJS recommend using the binaries to save time:
With a modern machine they mean > 4 cores, > 8gb mem I think. I tried it on a micro AWS instance and gave up after 2 hours.
In short: install the prebuilt packages from the PhantomJS site per their instructions.
就我个人而言,我更喜欢使用
npm
(请参阅 Arnel Bucio 答案)但是!我注意到一些
npm
模块仍然无法将其视为全局可执行文件。所以!
创建新的
/usr/share/phantomjs/
目录链接删除旧的
/usr/bin/phantomjs
可执行链接并创建新的一个Personaly I prefer using
npm
(see Arnel Bucio answer)but! I noticed that some of
npm
module still can't see it as global executable.so!
Create new
/usr/share/phantomjs/
directory linkRemove old
/usr/bin/phantomjs
executable link and create the new one在我的流浪引导中:
in my vagrant bootstrap:
我已经完成了这个。
I have done with this.
查看链接
安装指南位于...
并使用此命令在终端中运行
See link
Installation guide is in ...
And run in terminal with this command
来自官方网站:phantomjs 网站
From the official site: phantomjs site
对于 Ubuntu,请从 http://phantomjs.org/download.html 下载合适的文件。 CD 到下载的文件夹。然后:
确保将这些命令中的文件名替换为您已下载的文件。
For Ubuntu, download the suitable file from http://phantomjs.org/download.html. CD to the downloaded folder. Then:
Make sure to replace the file name in these commands with the file you have downloaded.
请注意,这绝对是一种方法:
遗憾的是,它安装的是 1.6,而不是最新的,但这适用于我的目的。
Be aware this is definitely one way to do it:
Sadly, it installs 1.6 and not the latest one, but this works for my purposes.
我知道这太旧了,但是,如果现在有人从 Google 得到这个问题,你可以通过输入 apt-get install phantomjs 来安装它
I know this is too old, but, just i case someone gets to this question from Google now, you can install it by typing apt-get install phantomjs
在 Windows 版 Ubuntu 上,我发现 apt-get 和 npm 版本都不适合我。有效的是此评论中的脚本。
为了便于使用,我将整个内容粘贴到名为
install_phantomjs.sh
的脚本文件中,使其可执行 (chmod u+x install_phantomjs.sh
),然后运行它(./install_phantomjs.sh
)On Ubuntu for Windows, I found neither
apt-get
nornpm
versions worked for me. What worked was the script from this comment.For ease of use, I pasted the whole thing into a script file called
install_phantomjs.sh
, made it executable (chmod u+x install_phantomjs.sh
), and then ran it (./install_phantomjs.sh
)或者最新的 - 32 位版本 Linux
Or the latest - 32bit version Linux
安装和调用Phantomjs
按照步骤操作不行,但是克隆了由其他人建造。 (版本2.0)
Installation and Calling Phantomjs
Follow the steps doesn't work, but cloned from others built. (ver2.0)
以下是 Julio Napurí 的安装过程 https://gist.github.com/julionc
版本:1.9.8
平台:x86_64
首先,安装或更新到最新的系统软件。
安装 PhantomJS 所需的这些软件包才能正常工作。
从 PhantomJS 网站获取。
下载后,将 Phantomjs 文件夹移动到 /usr/local/share/ 并创建一个符号链接:
现在,它应该在您的系统上正确安装了 PhantomJS。
Bellow the installation procedure by Julio Napurí https://gist.github.com/julionc
Version: 1.9.8
Platform: x86_64
First, install or update to the latest system software.
Install these packages needed by PhantomJS to work correctly.
Get it from the PhantomJS website.
Once downloaded, move Phantomjs folder to /usr/local/share/ and create a symlink:
Now, It should have PhantomJS properly on your system.
我发现了这种更简单的方法 - Phantom dependency + Npm
和 npm
Done。
I have found this simpler way - Phantom dependencies + Npm
and npm
Done.
在linux上运行hello.js不要忘记添加hello.js的路径:
phantomjs YourPathToPhantomjsFolder/examples/hello.js
On linux to run hello.js don't forget to add the path of hello.js:
phantomjs YourPathToPhantomjsFolder/examples/hello.js
如果你想轻松使用phantomjs,你可以在phantomjscloud.com使用它
只需通过http请求即可得到结果。
If you want to use phantomjs easily, you can use it at phantomjscloud.com
You can get the result just by http request.
这就是我将特定版本的 phantomjs 放置在 docker 容器的 /usr/local/bin 中的方法。
或不带
./
,具体取决于操作系统。This is how I place a specific version of phantomjs in /usr/local/bin on my docker containers.
or with out
./
depending on OS.您无需
sudo
或npm
即可启动并运行。只需下载、解压和添加到路径即可。如果您有备份整个主文件夹的习惯(我强烈推荐),那么这还有一个轻松备份的额外优势。这也适用于任何版本的 Linux。
缺点是:
您可以使用非常简单的 shell 脚本来安装/升级
或者在 Dockerfile 中
You can get up and running without
sudo
ornpm
. Simply download, extract, and add to path.This has the added advantage of easy backup if you are in the habit of backing up your entire home folder which I highly recommend. This also works with any version of Linux.
The disadvantages are:
You could use a very simple shell script for installing/upgrading
Or in a Dockerfile
这就是我所做的
在我的 ubuntu 16.04 机器上
,最后当我这样做时,
我得到了 2.1.1
在查看了该线程的每个答案后, 。我认为这是在 ubuntu 中安装和运行 phantomjs 的最佳解决方案。
Here is what I did
on my ubuntu 16.04 machine
and finally when I do
I get 2.1.1
After going through every answer of this thread. I think this is the best solution for installing and running phantomjs in ubuntu.