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

See link Installation guide is in ...

https://gist.github.com/julionc/7476620

And run in terminal with this command

phantomjs --webdriver=4444

查看更多
爷、活的狠高调
3楼-- · 2019-01-03 19:45

You can get up and running without sudo or npm. 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.

➤  cd ~
➤  wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
➤  mkdir phantomjs
➤  tar xjf phantomjs-2.1.1-linux-x86_64.tar.bz2 -C phantomjs
➤  echo 'export PATH="$PATH:$HOME/phantomjs/bin"' >> .profile
➤  source .profile
➤  phantomjs -v
2.1.1

The disadvantages are:

  1. You will need to manually upgrade
  2. Other users will not have access to this.

You could use a very simple shell script for installing/upgrading

#!/bin/sh
# install_phantomjs.sh $VERSION

$VERSION = $1
printf "Downloading PhantomJS $VERSION...\n"
wget "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$VERSION-linux-x86_64.tar.bz2"

printf "Extracting PhantomJS $VERSION to ~/phantomjs...\n"
mkdir ~/phantomjs
tar xjf phantomjs-$VERSION-linux-x86_64.tar.bz2 -C ~/phantomjs

printf "Done! Make sure $HOME/phantomjs/bin is in your path.\n"

Or in a Dockerfile

# Download and setup PhantomJS
ENV PHANTOMJS_VERSION 2.1.1
RUN curl -fSL "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2" -o /tmp/phantomjs.tar.bz2 && \
  mkdir ~/phantomjs && \
  tar xjf /tmp/phantomjs.tar.bz2 -C ~/phantomjs && \
  rm /tmp/phantomjs.tar.bz2
ENV PATH /home/$USERNAME/phantomjs/bin:$PATH
查看更多
Ridiculous、
4楼-- · 2019-01-03 19:46

If you want to use phantomjs easily, you can use it at phantomjscloud.com You can get the result just by http request.

查看更多
孤傲高冷的网名
5楼-- · 2019-01-03 19:47

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:

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.

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.

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

Installation and Calling Phantomjs

Follow the steps doesn't work, but cloned from others built. (ver2.0)

查看更多
Anthone
7楼-- · 2019-01-03 19:50

This is how I place a specific version of phantomjs in /usr/local/bin on my docker containers.

curl -Ls https://github.com/Medium/phantomjs/releases/download/v1.9.19/phantomjs-1.9.8-linux-x86_64.tar.bz2 \
    | tar jxvf - --strip-components=2 -C /usr/local/bin/ ./phantomjs-1.9.8-linux-x86_64/bin/phantomjs

or with out ./ depending on OS.

curl -Ls https://github.com/Medium/phantomjs/releases/download/v1.9.19/phantomjs-1.9.8-linux-x86_64.tar.bz2 \
    | tar jxvf - --strip-components=2 -C /usr/local/bin/ phantomjs-1.9.8-linux-x86_64/bin/phantomjs
查看更多
登录 后发表回答