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
@tcardonne

This comment has been minimized.

Copy link

@tcardonne tcardonne commented Sep 2, 2014

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
@aminelaadhari

This comment has been minimized.

@julionc

This comment has been minimized.

Copy link
Owner Author

@julionc julionc commented Sep 30, 2014

good catch!
I updated the gist. Thank you guys!

@karol-blaszczyk

This comment has been minimized.

Copy link

@karol-blaszczyk karol-blaszczyk commented Oct 1, 2014

Thank you, that was i was looking for !

@SizeSeeker

This comment has been minimized.

Copy link

@SizeSeeker SizeSeeker commented Oct 8, 2014

Great gist, thank you!

@shamabbas

This comment has been minimized.

Copy link

@shamabbas shamabbas commented Oct 27, 2014

Great! Thank you!

@iobee

This comment has been minimized.

Copy link

@iobee iobee commented Nov 19, 2014

Great! Thank you!

@lucassch

This comment has been minimized.

Copy link

@lucassch lucassch commented Nov 26, 2014

Great!

@reminate

This comment has been minimized.

Copy link

@reminate reminate commented Dec 9, 2014

Thank you!

@nikulkarni

This comment has been minimized.

Copy link

@nikulkarni nikulkarni commented Dec 15, 2014

exactly what I was looking for, thank you.

@georgehenze

This comment has been minimized.

Copy link

@georgehenze georgehenze commented Dec 27, 2014

Thanks a lot!

@talpa

This comment has been minimized.

Copy link

@talpa talpa commented Jan 4, 2015

@idmontie

This comment has been minimized.

Copy link

@idmontie idmontie commented Jan 10, 2015

👍
Thanks for this write up. Note that Phantom is now on 1.9.8 though.

@augnustin

This comment has been minimized.

Copy link

@augnustin augnustin commented Jan 20, 2015

Why triple symbolic link? Just in case?

What about sudo apt-get install phantomjs? It did not work for me, but any idea why?

@Yakito

This comment has been minimized.

Copy link

@Yakito Yakito commented Feb 3, 2015

Tested on an EC2 with Ubuntu 14.04, Works fine.

@lethalbrains

This comment has been minimized.

Copy link

@lethalbrains lethalbrains commented Feb 5, 2015

Thanx

@tbuchboeck

This comment has been minimized.

Copy link

@tbuchboeck tbuchboeck commented Feb 5, 2015

JFYI:
We had some font issues recently (Debian GNU/Linux 7.8 (wheezy) pjs-1.9.7)
Installing sudo apt-get install msttcorefonts solved the problem.

@q0rban

This comment has been minimized.

Copy link

@q0rban q0rban commented Feb 5, 2015

Thanks for this! You shouldn't need to create that many symlinks, or export your $PHANTOM_JS variable. I would just symlink to /usr/local/bin.

@q0rban

This comment has been minimized.

Copy link

@q0rban q0rban commented Feb 5, 2015

Here's a shorter version of the above:

sudo aptitude update
sudo aptitude install build-essential chrpath libssl-dev libxft-dev \
  libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev
PHANTOM_JS="phantomjs-1.9.8-linux-x86_64"
cd ~
wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
tar -xvjf $PHANTOM_JS.tar.bz2
sudo mv $PHANTOM_JS /usr/local/share
sudo ln -s /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
phantomjs --version
@tunnckoCore

This comment has been minimized.

Copy link

@tunnckoCore tunnckoCore commented Feb 6, 2015

After all

bash: /usr/local/bin/phantomjs: cannot execute binary file: Exec format error

Ubuntu 14.04

@tunnckoCore

This comment has been minimized.

Copy link

@tunnckoCore tunnckoCore commented Feb 6, 2015

Its okey. It was the arch :)

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Feb 13, 2015

q0rban: worked perfectly, thanks!

@pankajclabs

This comment has been minimized.

Copy link

@pankajclabs pankajclabs commented Feb 27, 2015

phantomjs --version

getting this:

Fontconfig warning: ignoring UTF-8: not a valid region tag
1.9.8

please help me out, I really tried everything

@mgzrobles

This comment has been minimized.

Copy link

@mgzrobles mgzrobles commented Mar 5, 2015

ubuntu
phantomjs --version
-bash: /usr/local/bin/phantomjs: cannot execute binary file

@jasseral

This comment has been minimized.

Copy link

@jasseral jasseral commented Mar 17, 2015

same !! :(
ubuntu
phantomjs --version
-bash: /usr/local/bin/phantomjs: cannot execute binary file

@jasseral

This comment has been minimized.

Copy link

@jasseral jasseral commented Mar 17, 2015

HELP !

@azenkovets

This comment has been minimized.

Copy link

@azenkovets azenkovets commented Mar 18, 2015

Have the same issue:
phantomjs --version
-bash: /usr/local/bin/phantomjs: cannot execute binary file

@TammoHeeren

This comment has been minimized.

Copy link

@TammoHeeren TammoHeeren commented Mar 18, 2015

you may need to download the i686 version
PHANTOM_JS="phantomjs-1.9.8-linux-i686"

@prakash89

This comment has been minimized.

Copy link

@prakash89 prakash89 commented Mar 19, 2015

Ubuntu
phantomjs --version
-bash: /usr/local/bin/phantomjs: cannot execute binary file

@prakash89

This comment has been minimized.

Copy link

@prakash89 prakash89 commented Mar 19, 2015

Thanks,
This works for me
PHANTOM_JS="phantomjs-1.9.8-linux-i686"

@julionc

This comment has been minimized.

Copy link
Owner Author

@julionc julionc commented Mar 20, 2015

I update this gist to v1.9.8.
For lazy ones like us. I attached install_phantomjs.sh script. Have fun!

@Rolos

This comment has been minimized.

Copy link

@Rolos Rolos commented Mar 29, 2015

Works perfectly, many thanks!

@id-den

This comment has been minimized.

Copy link

@id-den id-den commented Apr 9, 2015

Thanks!

@donaldali

This comment has been minimized.

Copy link

@donaldali donaldali commented Apr 13, 2015

Awesome

@dominiquedutra

This comment has been minimized.

Copy link

@dominiquedutra dominiquedutra commented Apr 17, 2015

Great stuff, thanks.

@ericallard0

This comment has been minimized.

Copy link

@ericallard0 ericallard0 commented Apr 20, 2015

Thanks !

@nhattan

This comment has been minimized.

Copy link

@nhattan nhattan commented Apr 21, 2015

Thanks!

@IvRRimum

This comment has been minimized.

Copy link

@IvRRimum IvRRimum commented Apr 30, 2015

install_phantomjs.sh - Works like charm, Thanks!

@xcaliburs

This comment has been minimized.

Copy link

@xcaliburs xcaliburs commented May 1, 2015

Thank you. Works fine, tested on EC2 with Ubuntu 14.04.

@vdloo

This comment has been minimized.

Copy link

@vdloo vdloo commented May 6, 2015

thanks!

@kumarldh

This comment has been minimized.

Copy link

@kumarldh kumarldh commented May 17, 2015

Or you can build it on your machine as suggested on the site and then follow instructions from this page where the author starts moving the folder.

@shashank-saxena

This comment has been minimized.

Copy link

@shashank-saxena shashank-saxena commented May 21, 2015

Thanks a ton!!!

@NL9

This comment has been minimized.

Copy link

@NL9 NL9 commented May 29, 2015

Thank you!

For fonts issue I have to install ttf-mscorefonts-installer too.

@carltondickson

This comment has been minimized.

Copy link

@carltondickson carltondickson commented May 29, 2015

Amazingly simple <3

@FurkanArslan

This comment has been minimized.

Copy link

@FurkanArslan FurkanArslan commented Jun 3, 2015

Thank you very much man! ☺️

@ftcosta

This comment has been minimized.

Copy link

@ftcosta ftcosta commented Jun 17, 2015

for Ubuntu14.04 and Mint

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
## system wide
sudo ln -s /usr/local/share/phantomjs-1.9.7-linux-x86_64/bin/phantomjs /usr/bin/phantomjs

phantomjs -v

v//carlosdeoliveira.guru

change the version from 1.9.7 to 1.9.8

@bushaman

This comment has been minimized.

Copy link

@bushaman bushaman commented Jun 17, 2015

Thanks ftcosta

@rbyelyy

This comment has been minimized.

Copy link

@rbyelyy rbyelyy commented Jun 26, 2015

Thanks. Works like a sharm ;-)

@n37r06u3

This comment has been minimized.

Copy link

@n37r06u3 n37r06u3 commented Jul 18, 2015

npm install phantomjs -g

@hebbian

This comment has been minimized.

Copy link

@hebbian hebbian commented Jul 23, 2015

pankajclabs, I know that feel buddy, when no one helps out

@rga-odoo

This comment has been minimized.

Copy link

@rga-odoo rga-odoo commented Jul 23, 2015

Thank you 👍

@kafeltz

This comment has been minimized.

Copy link

@kafeltz kafeltz commented Jul 28, 2015

The solution is so complex that I prefer using php -S localhost:80 for simple tests.

@lalitb

This comment has been minimized.

Copy link

@lalitb lalitb commented Aug 7, 2015

For all those who are getting error "Cannot execute binary file" , please note these instructions are only for 64 bit architecture. For 32 bit, you may have to build phantomjs from source.

@nroose

This comment has been minimized.

Copy link

@nroose nroose commented Oct 27, 2015

Thanks for this!

@Deele

This comment has been minimized.

Copy link

@Deele Deele commented Nov 10, 2015

Thank you! Just installed it in vagrant and it works.

@voodoorai2000

This comment has been minimized.

Copy link

@voodoorai2000 voodoorai2000 commented Nov 10, 2015

Thank you! It works 👍

@lu-ko

This comment has been minimized.

Copy link

@lu-ko lu-ko commented Nov 12, 2015

Problem: Fontconfig warning: ignoring UTF-8: not a valid region tag
Fix was in my case very simple, just add following variable to my bash profile: LC_ALL=en_US.UTF-8

@tonnydulo

This comment has been minimized.

Copy link

@tonnydulo tonnydulo commented Nov 14, 2015

Thanks for This

@adrianparr

This comment has been minimized.

Copy link

@adrianparr adrianparr commented Nov 16, 2015

Thanks for this. It worked for me.

@nando

This comment has been minimized.

Copy link

@nando nando commented Nov 24, 2015

👍

Thanks, thanks, thanks,
-- nando

@mwillerich

This comment has been minimized.

Copy link

@mwillerich mwillerich commented Dec 9, 2015

on Ubuntu 14.04 apt-get install phantomjs installs version 1.9.0-1 successfully for me.

@avral

This comment has been minimized.

Copy link

@avral avral commented Dec 15, 2015

Thank you very much =)

@dimanyc

This comment has been minimized.

Copy link

@dimanyc dimanyc commented Dec 24, 2015

works! Thanks!

@mkhusu

This comment has been minimized.

Copy link

@mkhusu mkhusu commented Jan 4, 2016

amazing stuff!
Thanks so much! Have been trying to figure this out for quite some time now

@jerryjohnjacob

This comment has been minimized.

Copy link

@jerryjohnjacob jerryjohnjacob commented Jan 4, 2016

Awesome!! 👍

@pette9

This comment has been minimized.

Copy link

@pette9 pette9 commented Jan 24, 2016

worked, Thank You 👍

@makshark

This comment has been minimized.

Copy link

@makshark makshark commented Feb 7, 2016

nice

@rotatopoti

This comment has been minimized.

Copy link

@rotatopoti rotatopoti commented Feb 10, 2016

thanks

@lucas1

This comment has been minimized.

Copy link

@lucas1 lucas1 commented Mar 7, 2016

Thanks

@aidankmcl

This comment has been minimized.

Copy link

@aidankmcl aidankmcl commented Mar 7, 2016

Just completed successfully with version 2.1.1, thanks!

@ethagnawl

This comment has been minimized.

Copy link

@ethagnawl ethagnawl commented Mar 7, 2016

Ha - and here I was worried this would be out-of-date...

But, seriously, this is incredibly useful. Thanks for putting it together and keeping it up-to-date!

@onliners

This comment has been minimized.

Copy link

@onliners onliners commented Mar 15, 2016

Thanks a lot!

@stefnats

This comment has been minimized.

Copy link

@stefnats stefnats commented Mar 17, 2016

Thanks! :-)

@vivex

This comment has been minimized.

Copy link

@vivex vivex commented Mar 28, 2016

Thanks

@MayankPratap

This comment has been minimized.

Copy link

@MayankPratap MayankPratap commented Apr 2, 2016

Thanks :)

@langri-sha

This comment has been minimized.

Copy link

@langri-sha langri-sha commented Apr 2, 2016

Thanks 😻! Everyone, don't forget to look at the latest gist revision 📝

@sridharkalaibala

This comment has been minimized.

Copy link

@sridharkalaibala sridharkalaibala commented Apr 3, 2016

Thanks a lot friend :)

@rimidl

This comment has been minimized.

Copy link

@rimidl rimidl commented Apr 11, 2016

Thanks!

@natanaugusto

This comment has been minimized.

Copy link

@natanaugusto natanaugusto commented Apr 27, 2016

Thanks! Very helpful

@yanshiyason

This comment has been minimized.

Copy link

@yanshiyason yanshiyason commented May 1, 2016

Thanks!!!

@amihaiemil

This comment has been minimized.

Copy link

@amihaiemil amihaiemil commented May 2, 2016

Great! Thank you very much!

@andyxmas

This comment has been minimized.

Copy link

@andyxmas andyxmas commented May 3, 2016

Worked like a charm on Ubuntu 14 getting version 2.1.1 of Phantom using https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2. Thanks!

@fawyna

This comment has been minimized.

Copy link

@fawyna fawyna commented May 19, 2016

Thanks for the simple guide!

@kennytilton

This comment has been minimized.

Copy link

@kennytilton kennytilton commented May 20, 2016

Brilliant.

@ghprod

This comment has been minimized.

Copy link

@ghprod ghprod commented May 30, 2016

Thanks :)

@achmadns

This comment has been minimized.

Copy link

@achmadns achmadns commented May 31, 2016

Thanks.

@baras

This comment has been minimized.

Copy link

@baras baras commented Jun 8, 2016

wget from Bitbucket sometimes results in a "20 redirection exceeded" error.
I would wget from github instead ( and get a newer version 😄 )

export PHANTOM_JS="phantomjs-2.1.1-linux-x86_64"
wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/$PHANTOM_JS.tar.bz2

and thanks for this Gist 👍

@JorgeRdg

This comment has been minimized.

Copy link

@JorgeRdg JorgeRdg commented Jun 14, 2016

Thanks for the Gist!

@enfeizhan

This comment has been minimized.

Copy link

@enfeizhan enfeizhan commented Jul 10, 2016

My sincere thanks. Heaps of instructions on the web but only yours works to me perfectly.

@a1exlism

This comment has been minimized.

Copy link

@a1exlism a1exlism commented Jul 14, 2016

Thanks for sharing.

@DanDvoracek

This comment has been minimized.

Copy link

@DanDvoracek DanDvoracek commented Jul 20, 2016

Thanks!

@nisevi

This comment has been minimized.

Copy link

@nisevi nisevi commented Aug 1, 2016

👍

@milad145

This comment has been minimized.

Copy link

@milad145 milad145 commented Aug 8, 2016

how can i uninstall phantomjs?

@adamwlev

This comment has been minimized.

Copy link

@adamwlev adamwlev commented Aug 9, 2016

Thank you!

@mathieujobin

This comment has been minimized.

Copy link

@mathieujobin mathieujobin commented Aug 16, 2016

Great script...
but this working curl command that worked for me

sudo curl --output /usr/local/bin/phantomjs https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1

from: https://discuss.circleci.com/t/add-phantomjs-2-1-1-to-the-platform/1755/4

@cankemik

This comment has been minimized.

Copy link

@cankemik cankemik commented Sep 5, 2016

@loretoparisi

This comment has been minimized.

Copy link

@loretoparisi loretoparisi commented Sep 5, 2016

So this is the updated script for 2.1.1 and the new tarball url

#!/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-2.1.1"
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://github.com/Medium/phantomjs/releases/download/v2.1.1/$PHANTOM_JS.tar.bz2
sudo tar xvjf $PHANTOM_JS.tar.bz2

sudo mv $PHANTOM_JS.tar.bz2 /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
@capitolkrs

This comment has been minimized.

Copy link

@capitolkrs capitolkrs commented Sep 11, 2016

Thank you for the gist

@mikesten

This comment has been minimized.

Copy link

@mikesten mikesten commented Sep 13, 2016

@loretoparisi Thanks for the update! Small typo towards the end of your script...

sudo mv $PHANTOM_JS.tar.bz2 /usr/local/share/ should be sudo mv $PHANTOM_JS /usr/local/share/

@arturmalecki

This comment has been minimized.

Copy link

@arturmalecki arturmalecki commented Oct 5, 2016

Good stuff 👍

@g8d3

This comment has been minimized.

Copy link

@g8d3 g8d3 commented Oct 5, 2016

Thanks @mathieujobin

@miked0004

This comment has been minimized.

Copy link

@miked0004 miked0004 commented Oct 7, 2016

Thanks for this. Since it runs as root, it does not need sudo.

I dumped this in a Dockerfile here: https://gist.github.com/miked0004/b4aa62b62afbb16c67528f7b5f520041

See the docker-compose.yml in that gist for an example of running the box to bundle and run rake.

@jmillxyz

This comment has been minimized.

Copy link

@jmillxyz jmillxyz commented Nov 1, 2016

Thanks @mikesten and @loretoparisi -- the bitbucket URL for wget does work for me.

@tregenza

This comment has been minimized.

Copy link

@tregenza tregenza commented Nov 19, 2016

Second to @mikesten comment on @loretoparisi 's script

sudo mv $PHANTOM_JS.tar.bz2 /usr/local/share/ should be sudo mv $PHANTOM_JS /usr/local/share/

Other than than the script works perfectly.

@FredyKonig

This comment has been minimized.

Copy link

@FredyKonig FredyKonig commented Nov 23, 2016

what about :
sudo apt-get install phantomjs

@rista404

This comment has been minimized.

Copy link

@rista404 rista404 commented Dec 2, 2016

Thanks @loretoparisi and @mikesten for the updated script, works great! 🎉

@ambikashri

This comment has been minimized.

Copy link

@ambikashri ambikashri commented Dec 7, 2016

I am getting the below error. Could somebody suggest what could be done. I am using ubuntu

customer@QA-Ubuntu-1:~/automation$ phantomjs --webdriver=8090 --webdriver-selenium-grid-hub=http://127.0.0.1:4444
QXcbConnection: Failed to initialize XRandr
Qt: XKEYBOARD extension not present on the X server.
[INFO - 2016-12-07T10:46:27.715Z] GhostDriver - Main - running on port 8090
[INFO - 2016-12-07T10:46:27.720Z] GhostDriver - Main - registering to Selenium HUB 'http://127.0.0.1:4444' version: using '127.0.0.1:8090' with org.openqa.grid.selenium.proxy.DefaultRemoteProxy as remote proxy. [ERROR - 2016-12-07T10:46:27.740Z] GhostDriver - main.fail - {"line":97,"stack":"register\nglobal code"}

@z

This comment has been minimized.

Copy link

@z z commented Dec 18, 2016

The other update for 2.1.1 had issues, I modified the script below:

#!/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-2.1.1"
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/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
@gautiermichelin

This comment has been minimized.

Copy link

@gautiermichelin gautiermichelin commented Dec 28, 2016

If this script has to be run through a sudo, why the sudo lines at the end ?
It's redundant...

Prefer :

#!/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-2.1.1"
ARCH=$(uname -m)

if ! [ $ARCH = "x86_64" ]; then
    $ARCH="i686"
fi

PHANTOM_JS="$PHANTOM_VERSION-linux-$ARCH"

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

cd ~
wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
tar xvjf $PHANTOM_JS.tar.bz2
mv $PHANTOM_JS /usr/local/share/
ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/share/phantomjs
ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin/phantomjs
ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/bin/phantomjs

@julionc nice and very useful gist :-) 👍

@ssi-anik

This comment has been minimized.

Copy link

@ssi-anik ssi-anik commented Jan 22, 2017

👍 for the post, and if anyone wants to download the latest one, go get the file name, and change the PHANTOM_JS variable.

@illia108

This comment has been minimized.

Copy link

@illia108 illia108 commented Jan 26, 2017

Thanks. Worked for me!

@bologer

This comment has been minimized.

Copy link

@bologer bologer commented Jan 26, 2017

Для тех, кто мучается установкой phantomjs 2.x.x на Ubuntu 14.00/if you cannot easily install phantomjs 2.x.x on Ubuntu — http://bologer.ru/kak-ustanovitobnovit-phantomjs-v-ubuntu-14-04/

@frankie-loves-jesus

This comment has been minimized.

Copy link

@frankie-loves-jesus frankie-loves-jesus commented Feb 4, 2017

Worked here as well, thanks for a wonderful thread!

@siddhantsomani

This comment has been minimized.

Copy link

@siddhantsomani siddhantsomani commented Mar 15, 2017

Worked perfectly !
Thanks !!

@janipaijanen

This comment has been minimized.

Copy link

@janipaijanen janipaijanen commented Mar 17, 2017

There happened something in the download for me and being lazy to cleaning up things, I thought it would be better to force things happen.

For phantomjs-2.1.1

#!/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-2.1.1"
ARCH=$(uname -m)

if ! [ $ARCH = "x86_64" ]; then
    $ARCH="i686"
fi

PHANTOM_JS="$PHANTOM_VERSION-linux-$ARCH"

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

cd ~
wget -q https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2 -O $PHANTOM_JS.tar.bz2
tar xvjf $PHANTOM_JS.tar.bz2

if [ -d /usr/local/share/$PHANTOM_JS ] ; then
  rm -rf /usr/local/share/$PHANTOM_JS
fi
mv -f $PHANTOM_JS /usr/local/share/
ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/share/phantomjs
ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin/phantomjs
ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/bin/phantomjs

@Lgofk

This comment has been minimized.

Copy link

@Lgofk Lgofk commented Apr 14, 2017

very helpful! Thanks ;)

@diego-augusto

This comment has been minimized.

Copy link

@diego-augusto diego-augusto commented Apr 25, 2017

Thanks!

@alihesari

This comment has been minimized.

Copy link

@alihesari alihesari commented Apr 28, 2017

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

npm install -g phantomjs-prebuilt

@mbriceno

This comment has been minimized.

Copy link

@mbriceno mbriceno commented May 15, 2017

Perfect! thank a lot!!

@skylerto

This comment has been minimized.

Copy link

@skylerto skylerto commented Jun 5, 2017

❤️

@nateGeorge

This comment has been minimized.

Copy link

@nateGeorge 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

This comment has been minimized.

Copy link

@bchschaefer 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

This comment has been minimized.

Copy link

@pedrocaseiro pedrocaseiro commented Aug 31, 2017

Awesome!

@Unayung

This comment has been minimized.

Copy link

@Unayung Unayung commented Sep 5, 2017

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

@ManuelTS

This comment has been minimized.

Copy link

@ManuelTS 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

This comment has been minimized.

Copy link

@jhonattasantos jhonattasantos commented Nov 22, 2017

Thanks a lot!

@ghost

This comment has been minimized.

Copy link

@ghost 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

This comment has been minimized.

Copy link

@akilawickey akilawickey commented Mar 27, 2018

Cool Thanks

@b3none

This comment has been minimized.

Copy link

@b3none b3none commented Jun 7, 2018

You saved me!

@iamvinny

This comment has been minimized.

Copy link

@iamvinny iamvinny commented Jun 15, 2018

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

@julesmqz

This comment has been minimized.

Copy link

@julesmqz julesmqz commented Sep 2, 2018

Thank you very much. working now

@code2exe

This comment has been minimized.

Copy link

@code2exe code2exe commented Mar 9, 2019

Thanks

@Ronaldomata34

This comment has been minimized.

Copy link

@Ronaldomata34 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

This comment has been minimized.

Copy link

@cristhian-net cristhian-net commented Oct 15, 2019

it worked perfectly, thanks

@dhatGuy

This comment has been minimized.

Copy link

@dhatGuy 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

This comment has been minimized.

Copy link

@DrakeSeven 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

This comment has been minimized.

Copy link

@CaioPenhalver CaioPenhalver commented Apr 8, 2020

Cool!!! Thank you!!

@tmanok

This comment has been minimized.

Copy link

@tmanok tmanok commented Apr 14, 2020

Thanks so much for your help!!

@xElkomy

This comment has been minimized.

Copy link

@xElkomy 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

This comment has been minimized.

Copy link

@kaka-ruto 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

@juloko

This comment has been minimized.

Copy link

@juloko juloko commented Oct 7, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.