Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to install PhantomJS on Debian/Ubuntu

How to install PhantomJS on Ubuntu

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
#!/usr/bin/env bash
# This script install PhantomJS in your Debian/Ubuntu System
#
# This script must be run as root:
# sudo sh install_phantomjs.sh
#
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
PHANTOM_VERSION="phantomjs-1.9.8"
ARCH=$(uname -m)
if ! [ $ARCH = "x86_64" ]; then
$ARCH="i686"
fi
PHANTOM_JS="$PHANTOM_VERSION-linux-$ARCH"
sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev -y
sudo apt-get install libfreetype6 libfreetype6-dev -y
sudo apt-get install libfontconfig1 libfontconfig1-dev -y
cd ~
wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2
sudo mv $PHANTOM_JS /usr/local/share
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
@diego-augusto
Copy link

diego-augusto commented Apr 25, 2017

Thanks!

@alihesari
Copy link

alihesari commented Apr 28, 2017

PhantomJS is on npm. You can run this command to install it globally:

npm install -g phantomjs-prebuilt

@mbriceno
Copy link

mbriceno commented May 15, 2017

Perfect! thank a lot!!

@skylerto
Copy link

skylerto commented Jun 5, 2017

❤️

@nateGeorge
Copy link

nateGeorge commented Jun 13, 2017

Dude, awesome. Would be cool though if it grabbed the latest version automatically, since now we're at 2.1.1. But I guess if npm works, then that is easier than writing your own script.

@bchschaefer
Copy link

bchschaefer commented Jul 24, 2017

@nateGeorge

Just my quick&dirty one liner to grab the latest, non-beta, 64bit archive name:

PHANTOM_JS_LATEST=$(curl -s https://bitbucket.org/ariya/phantomjs/downloads/ | grep -i -e zip -e bz2 | grep -vi beta | grep -i linux-x86_64 | grep -v symbols | cut -d '>' -f 2 | cut -d '<' -f 1 | head -n 1)

@pedrocaseiro
Copy link

pedrocaseiro commented Aug 31, 2017

Awesome!

@Unayung
Copy link

Unayung commented Sep 5, 2017

Thank you so much !!!! @janipaijanen. ❤️ ❤️ ❤️

@ManuelTS
Copy link

ManuelTS commented Sep 28, 2017

With the version of @janipaijanen you will have the tar.bz2 file lying around in your home folder. I used /tmp/ instead to delete it automatically when the computer shuts down.

Thanks a ton @janipaijanen!

Here the changed gist:
https://gist.github.com/ManuelTS/935155f423374e950566d05d1448038d

@jhonattasantos
Copy link

jhonattasantos commented Nov 22, 2017

Thanks a lot!

Copy link

ghost commented Nov 27, 2017

Thank a lot!

I do some modification from your script for dockerizing purpose

https://gist.github.com/mappuj1/31e6dea39d48d56c74ead82177fd0523

@akilawickey
Copy link

akilawickey commented Mar 27, 2018

Cool Thanks

@b3none
Copy link

b3none commented Jun 7, 2018

You saved me!

@iamvinny
Copy link

iamvinny commented Jun 15, 2018

Why the fixed version though? PhantomJS has been updated, the currently version is 2.1.1.

@julesmqz
Copy link

julesmqz commented Sep 2, 2018

Thank you very much. working now

@code2exe
Copy link

code2exe commented Mar 9, 2019

Thanks

@Ronaldomata34
Copy link

Ronaldomata34 commented Jul 17, 2019

There is a mistake :

sudo mv $PHANTOM_JS.tar.bz2 /usr/local/share/
cd /usr/local/share/
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/share/phantomjs
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/bin/phantomjs

should be :

sudo mv $PHANTOM_JS.tar.bz2 /usr/local/share/
cd /usr/local/share/
sudo tar xvjf phantomjs-1.9.2-linux-x86_64.tar.bz2
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/share/phantomjs
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/bin/phantomjs

replace:

> sudo tar xvjf phantomjs-1.9.2-linux-x86_64.tar.bz2
with:

> sudo tar xvjf $PHANTOM_JS.tar.bz2

@cristhian-net
Copy link

cristhian-net commented Oct 15, 2019

it worked perfectly, thanks

@dhatGuy
Copy link

dhatGuy commented Oct 20, 2019

Each time I try to run sudo tar xvjf $PHANTOM_JS.tar.bz2, I get this error

`
phantomjs-2.1.1-linux-x86_64/
phantomjs-2.1.1-linux-x86_64/examples/
phantomjs-2.1.1-linux-x86_64/examples/colorwheel.js
phantomjs-2.1.1-linux-x86_64/examples/scandir.js
phantomjs-2.1.1-linux-x86_64/examples/page_events.js
phantomjs-2.1.1-linux-x86_64/examples/loadspeed.js
phantomjs-2.1.1-linux-x86_64/examples/injectme.js
phantomjs-2.1.1-linux-x86_64/examples/render_multi_url.js
phantomjs-2.1.1-linux-x86_64/examples/server.js
phantomjs-2.1.1-linux-x86_64/examples/netlog.js
phantomjs-2.1.1-linux-x86_64/examples/pagecallback.js
phantomjs-2.1.1-linux-x86_64/examples/module.js
phantomjs-2.1.1-linux-x86_64/examples/arguments.js
phantomjs-2.1.1-linux-x86_64/examples/universe.js
phantomjs-2.1.1-linux-x86_64/examples/openurlwithproxy.js
phantomjs-2.1.1-linux-x86_64/examples/sleepsort.js
phantomjs-2.1.1-linux-x86_64/examples/modernizr.js
phantomjs-2.1.1-linux-x86_64/examples/unrandomize.js
phantomjs-2.1.1-linux-x86_64/examples/hello.js
phantomjs-2.1.1-linux-x86_64/examples/stdin-stdout-stderr.js
phantomjs-2.1.1-linux-x86_64/examples/fibo.js
phantomjs-2.1.1-linux-x86_64/examples/phantomwebintro.js
phantomjs-2.1.1-linux-x86_64/examples/echoToFile.js
phantomjs-2.1.1-linux-x86_64/examples/post.js
phantomjs-2.1.1-linux-x86_64/examples/loadurlwithoutcss.js
phantomjs-2.1.1-linux-x86_64/examples/child_process-examples.js
phantomjs-2.1.1-linux-x86_64/examples/printenv.js
phantomjs-2.1.1-linux-x86_64/examples/useragent.js
phantomjs-2.1.1-linux-x86_64/examples/rasterize.js
phantomjs-2.1.1-linux-x86_64/examples/outputEncoding.js
phantomjs-2.1.1-linux-x86_64/examples/waitfor.js
phantomjs-2.1.1-linux-x86_64/examples/serverkeepalive.js
phantomjs-2.1.1-linux-x86_64/examples/postserver.js
phantomjs-2.1.1-linux-x86_64/examples/printmargins.js
phantomjs-2.1.1-linux-x86_64/examples/version.js
phantomjs-2.1.1-linux-x86_64/examples/run-qunit.js
phantomjs-2.1.1-linux-x86_64/examples/features.js
phantomjs-2.1.1-linux-x86_64/examples/netsniff.js
phantomjs-2.1.1-linux-x86_64/examples/walk_through_frames.js
phantomjs-2.1.1-linux-x86_64/examples/printheaderfooter.js
phantomjs-2.1.1-linux-x86_64/examples/responsive-screenshot.js
phantomjs-2.1.1-linux-x86_64/examples/countdown.js
phantomjs-2.1.1-linux-x86_64/examples/detectsniff.js
phantomjs-2.1.1-linux-x86_64/examples/simpleserver.js
phantomjs-2.1.1-linux-x86_64/examples/postjson.js
phantomjs-2.1.1-linux-x86_64/examples/run-jasmine2.js
phantomjs-2.1.1-linux-x86_64/examples/run-jasmine.js
phantomjs-2.1.1-linux-x86_64/README.md
phantomjs-2.1.1-linux-x86_64/LICENSE.BSD
phantomjs-2.1.1-linux-x86_64/bin/
phantomjs-2.1.1-linux-x86_64/bin/phantomjs

bzip2: Compressed file ends unexpectedly;
perhaps it is corrupted? Possible reason follows.
bzip2: Inappropriate ioctl for device
Input file = (stdin), output file = (stdout)

It is possible that the compressed file(s) have become corrupted.
You can use the -tvv option to test integrity of such files.

You can use the `bzip2recover' program to attempt to recover
data from undamaged sections of corrupted files.

tar: Unexpected EOF in archive
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now `

@DrakeSeven
Copy link

DrakeSeven commented Feb 26, 2020

On Debian 10.3.0 Buster I got Autoconfiguration failed:

139743462616704:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(libssl_conf.so): libssl_conf.so: cannot open shared object file: No such file or directory 139743462616704:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244: 139743462616704:error:0E07506E:configuration file routines:MODULE_LOAD_DSO:error loading dso:conf_mod.c:285:module=ssl_conf, path=ssl_conf 139743462616704:error:0E076071:configuration file routines:MODULE_RUN:unknown module name:conf_mod.c:222:module=ssl_confauto configuration

Solution:
open /etc/ssl/openssl.cnf and comment out the line under [default_conf] (it is at the end of the config file):
#ssl_conf = ssl_sect

I found this solution on this russian blog page. I guess if you are running OpenSSL version 1.1.1d you have to comment out this line to make it work.

@CaioPenhalver
Copy link

CaioPenhalver commented Apr 8, 2020

Cool!!! Thank you!!

@tmanok
Copy link

tmanok commented Apr 14, 2020

Thanks so much for your help!!

@xElkomy
Copy link

xElkomy commented Apr 28, 2020

any help with that ERROR:-
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

PhantomJS has crashed. Please read the bug reporting guide at
http://phantomjs.org/bug-reporting.html and file a bug report.
Aborted (core dumped)

@kaka-ruto
Copy link

kaka-ruto commented Sep 30, 2020

Thanks! Worked for me.

I just had to chmod +x install_phantomjs.sh for me to avoid using sudo in the server

@julioflima
Copy link

julioflima commented Oct 7, 2020

@DrakeSeven man you are awsome!!!!!!!!!!!

@pdelteil
Copy link

pdelteil commented Apr 23, 2021

Works correctly in Ubuntu 20.10.

@mateusleon
Copy link

mateusleon commented May 28, 2021

Worked on WSL 2 for Windows 10 Home, 21H1, 19043.1023, Windows Feature Experience Pack 120.2212.3740.0.

To install the most recent version of phantomjs and phantomjs-prebuilt (phantomjs@^2.1.7 and phantomjs-prebuilt@^2.1.16), I needed to use PhantomJS@2.1.1 for Linux 64-bits (https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2).

@defra91
Copy link

defra91 commented Jul 27, 2021

Thank you very much!

@paulsalmon-za
Copy link

paulsalmon-za commented Aug 31, 2021

On Debian 10.3.0 Buster I got Autoconfiguration failed:

139743462616704:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(libssl_conf.so): libssl_conf.so: cannot open shared object file: No such file or directory 139743462616704:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244: 139743462616704:error:0E07506E:configuration file routines:MODULE_LOAD_DSO:error loading dso:conf_mod.c:285:module=ssl_conf, path=ssl_conf 139743462616704:error:0E076071:configuration file routines:MODULE_RUN:unknown module name:conf_mod.c:222:module=ssl_confauto configuration

Solution:
open /etc/ssl/openssl.cnf and comment out the line under [default_conf] (it is at the end of the config file):
#ssl_conf = ssl_sect

I found this solution on this russian blog page. I guess if you are running OpenSSL version 1.1.1d you have to comment out this line to make it work.

I've found another solution without changing the default ssl settings here

I've used it in a docker containers, so adding ENV OPENSSL_CONF=/etc/ssl/ solved this particular issue for me

@aleenprd
Copy link

aleenprd commented Nov 24, 2021

Thank youuu!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment