Linux 如何在 Ubuntu 上设置和运行 PhantomJS?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8778513/
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
How can I setup & run PhantomJS on Ubuntu?
提问by FURKAN ILGIN
I set up PhantomJS and recorded it to video: https://www.dailymotion.com/video/xnizmh_1_webcam
我设置了 PhantomJS 并将其录制为视频:https: //www.dailymotion.com/video/xnizmh_1_webcam
Build instructions: http://phantomjs.org/build.html
构建说明:http: //phantomjs.org/build.html
Is there anything wrong in my setup?
我的设置有什么问题吗?
After I set it up I read the quick start tutorialand tried to write this code
设置完成后,我阅读了快速入门教程并尝试编写此代码
phantomjs hello.js
It gives me "command not found" error. How can I solve this problem?
它给了我“找不到命令”错误。我怎么解决这个问题?
采纳答案by shawn
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.
Guidouil 的回答让我走上了正轨。我不得不向 /usr/bin/ 添加一个额外的符号链接,并且我为所有 3 个都做了直接符号链接 - 见下文。
I'm installing on Ubuntu server Natty Narwhal.
我正在 Ubuntu 服务器 Natty Narwhal 上安装。
This is exactly what I did.
这正是我所做的。
cd /usr/local/share
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2
sudo tar xjf phantomjs-1.9.7-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
And finally when I do
最后当我做
phantomjs -v
I get 1.9.7
我得到 1.9.7
If anyone sees any problems with what I've done, please let me know.
如果有人发现我所做的有任何问题,请告诉我。
回答by Vijay Boyapati
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):
以下是我使用的构建步骤(请注意,这些说明适用于 1.3 版。有关最新 PhantomJS 的安装说明,请参阅对此答案的评论):
sudo apt-get update
sudo apt-get install git-core
sudo apt-get install build-essential
sudo apt-get install libqt4-dev libqtwebkit-dev qt4-qmake
git clone git://github.com/ariya/phantomjs.git && cd phantomjs
git checkout 1.3
qmake-qt4 && make
sudo apt-get install xvfb xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
Launch Xvfb:Xvfb :23 -screen 0 1024x768x24 &
启动 Xvfb:Xvfb :23 -screen 0 1024x768x24 &
Now run phantom:DISPLAY=:23 ./phantomjs hello.js
现在运行幻象:DISPLAY=:23 ./phantomjs hello.js
回答by NBK
For PhantomJS version above 1.5, consider this (verbatim copy of the build instructions on the phantom website):
对于 1.5 以上的 PhantomJS 版本,请考虑这个(phantom 网站上构建说明的逐字副本):
For Ubuntu Linux (tested on a barebone install of Ubuntu 10.04 Lucid Lynx and Ubuntu 11.04 Natty Narwhal):
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev git clone git://github.com/ariya/phantomjs.git cd phantomjs git checkout 1.7 ./build.sh
对于 Ubuntu Linux(在 Ubuntu 10.04 Lucid Lynx 和 Ubuntu 11.04 Natty Narwhal 的准系统安装上测试):
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev git clone git://github.com/ariya/phantomjs.git cd phantomjs git checkout 1.7 ./build.sh
回答by iwein
For Ubuntu you can use the prebuilt versions downloadable from the PhantomJS site.
对于 Ubuntu,您可以使用可从 PhantomJS 站点下载的预构建版本。
If you have some serious time on your hands you can also build it yourself. (This is exactly the procedure from Nikhil's answer).
如果您手头上有一些严肃的时间,您也可以自己构建它。(这正是 Nikhil 回答中的程序)。
The guys over at PhantomJS recommend using the binaries to save time:
PhantomJS 的人建议使用二进制文件来节省时间:
Warning: Compiling PhantomJS from source takes a long time, mainly due to thousands of files in the WebKit module. With 4 parallel compile jobs on a modern machine, the entire process takes roughly 30 minutes. It is highly recommended to download and install the ready-made binary package if it is available.
警告:从源代码编译 PhantomJS 需要很长时间,主要是由于 WebKit 模块中有数千个文件。在现代机器上有 4 个并行编译作业,整个过程大约需要 30 分钟。如果有现成的二进制包,强烈建议下载并安装。
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.
对于现代机器,它们意味着 > 4 核,我认为 > 8gb mem。我在微型 AWS 实例上尝试过,2 小时后放弃了。
In short: install the prebuilt packages from the PhantomJS site per their instructions.
简而言之:按照他们的说明从 PhantomJS 站点安装预构建的包。
回答by iwein
Install from package manager:
从包管理器安装:
sudo apt-get install phantomjs
回答by Guidouil
download from phantomjs website the prebuilt package : http://phantomjs.org/download.htmlthen open a terminal and go to the Downloads folder
从 phantomjs 网站下载预构建包:http://phantomjs.org/download.html 然后打开终端并转到下载文件夹
sudo mv phantomjs-1.8.1-linux-x86_64.tar.bz2 /usr/local/share/.
cd /usr/local/share/
sudo tar xjf phantomjs-1.8.1-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.8.1-linux-x86_64 /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
then to check install phantomjs -v
should return 1.8.1
然后检查安装phantomjs -v
应该返回1.8.1
回答by Igor Shubin
From the official site: phantomjs site
来自官方网站:phantomjs 网站
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.8
./build.sh
回答by Amar Banerjee
I have done with this.
我已经完成了这个。
sudo apt-get update
sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
./build.sh
回答by Humming
For Ubuntu, download the suitable file from http://phantomjs.org/download.html. CD to the downloaded folder. Then:
对于 Ubuntu,请从http://phantomjs.org/download.html下载合适的文件。CD 到下载的文件夹。然后:
sudo tar xvf phantomjs-1.9.0-linux-x86_64.tar.bz2
sudo mv phantomjs-1.9.0-linux-x86_64 /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs/bin/phantomjs /usr/bin/phantomjs
Make sure to replace the file name in these commands with the file you have downloaded.
确保将这些命令中的文件名替换为您下载的文件。
回答by Nesha Zoric
Or the latest - 32bit version Linux
或者最新的——32位版Linux
sudo wget http://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-i686.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.9.2-linux-i686/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.2-linux-i686/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-1.9.2-linux-i686/bin/phantomjs /usr/bin/phantomjs