How can I setup & run PhantomJS on Ubuntu?

2019-01-03 19:11发布

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?

25条回答
手持菜刀,她持情操
2楼-- · 2019-01-03 19:51

On linux to run hello.js don't forget to add the path of hello.js:

phantomjs YourPathToPhantomjsFolder/examples/hello.js

查看更多
看我几分像从前
3楼-- · 2019-01-03 19:54

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.

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

If anyone sees any problems with what I've done, please let me know.

查看更多
欢心
4楼-- · 2019-01-03 19:56

in my vagrant bootstrap:

apt-get install -y build-essential chrpath git-core libssl-dev libfontconfig1-dev
git clone git://github.com/ariya/phantomjs.git
cd phantomjs
git checkout 1.9
echo y | ./build.sh
ln -s /home/vagrant/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
cd ..
查看更多
姐就是有狂的资本
5楼-- · 2019-01-03 19:58

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):

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

Now install Xvfb

sudo apt-get install xvfb xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic

Launch Xvfb:
Xvfb :23 -screen 0 1024x768x24 &

Now run phantom:
DISPLAY=:23 ./phantomjs hello.js

查看更多
贼婆χ
6楼-- · 2019-01-03 19:58

For Ubuntu, download the suitable file from http://phantomjs.org/download.html. CD to the downloaded folder. Then:

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.

查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-01-03 19:59

Be aware this is definitely one way to do it:

$ sudo apt-get install phantomjs
$ phantomjs -v
1.6.0

Sadly, it installs 1.6 and not the latest one, but this works for my purposes.

查看更多
登录 后发表回答