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条回答
We Are One
2楼-- · 2019-01-03 19:40

Install from package manager:

sudo apt-get install phantomjs
查看更多
对你真心纯属浪费
3楼-- · 2019-01-03 19:41

Personaly I prefer using npm (see Arnel Bucio answer)

sudo npm install -g phantomjs

but! I noticed that some of npm module still can't see it as global executable.

enter image description here

so!

  • Create new /usr/share/phantomjs/ directory link

    cd /usr/share
    sudo ln -s ../lib/node_modules/phantomjs/lib/phantom phantomjs
    
  • Remove old /usr/bin/phantomjs executable link and create the new one

    cd /usr/bin
    sudo mv phantomjs phantomjs.old
    sudo ln -s ../share/phantomjs .
    
查看更多
女痞
4楼-- · 2019-01-03 19:41

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.

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev

Install these packages needed by PhantomJS to work correctly.

sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install libfontconfig1 libfontconfig1-dev

Get it from the PhantomJS website.

cd ~
export PHANTOM_JS="phantomjs-1.9.8-linux-x86_64"
wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2

Once downloaded, move Phantomjs folder to /usr/local/share/ and create a symlink:

sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin

Now, It should have PhantomJS properly on your system.

phantomjs --version
查看更多
Root(大扎)
5楼-- · 2019-01-03 19:41

I have found this simpler way - Phantom dependencies + Npm

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev
sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install libfontconfig1 libfontconfig1-dev

and npm

[sudo] npm install -g phantomjs

Done.

查看更多
虎瘦雄心在
6楼-- · 2019-01-03 19:43

For PhantomJS version above 1.5, consider this (verbatim copy of the build instructions on the phantom website):

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
查看更多
Viruses.
7楼-- · 2019-01-03 19:43

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
查看更多
登录 后发表回答