Create a gist now

Instantly share code, notes, and snippets.

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

SmurfyFR 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
Owner

julionc commented Sep 30, 2014

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

Thank you, that was i was looking for !

Great gist, thank you!

Great! Thank you!

iobee commented Nov 19, 2014

Great! Thank you!

Great!

reminate commented Dec 9, 2014

Thank you!

exactly what I was looking for, thank you.

Thanks a lot!

๐Ÿ‘
Thanks for this write up. Note that Phantom is now on 1.9.8 though.

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 commented Feb 3, 2015

Tested on an EC2 with Ubuntu 14.04, Works fine.

Thanx

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

After all

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

Ubuntu 14.04

Its okey. It was the arch :)

@ghost

ghost commented Feb 13, 2015

q0rban: worked perfectly, thanks!

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

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

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

HELP !

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

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

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

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

Owner

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 commented Mar 29, 2015

Works perfectly, many thanks!

id-den commented Apr 9, 2015

Thanks!

Awesome

Great stuff, thanks.

Thanks !

nhattan commented Apr 21, 2015

Thanks!

install_phantomjs.sh - Works like charm, Thanks!

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

vdloo commented May 6, 2015

thanks!

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.

Thanks a ton!!!

Plazik commented May 29, 2015

Thank you!

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

Amazingly simple <3

Thank you very much man! โ˜บ๏ธ

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

Thanks ftcosta

rbyelyy commented Jun 26, 2015

Thanks. Works like a sharm ;-)

npm install phantomjs -g

hebbian commented Jul 23, 2015

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

Thank you ๐Ÿ‘

kafeltz commented Jul 28, 2015

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

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 commented Oct 27, 2015

Thanks for this!

Deele commented Nov 10, 2015

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

Thank you! It works ๐Ÿ‘

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

Thanks for This

Thanks for this. It worked for me.

nando commented Nov 24, 2015

๐Ÿ‘

Thanks, thanks, thanks,
-- nando

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

avral commented Dec 15, 2015

Thank you very much =)

dimanyc commented Dec 24, 2015

works! Thanks!

mkhusu commented Jan 4, 2016

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

Awesome!! ๐Ÿ‘

pette9 commented Jan 24, 2016

worked, Thank You ๐Ÿ‘

makshark commented Feb 7, 2016

nice

thanks

lucas1 commented Mar 7, 2016

Thanks

Just completed successfully with version 2.1.1, thanks!

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!

Thanks a lot!

Thanks! :-)

vivex commented Mar 28, 2016

Thanks

Thanks :)

Thanks ๐Ÿ˜ป! Everyone, don't forget to look at the latest gist revision ๐Ÿ“

Thanks a lot friend :)

rimidl commented Apr 11, 2016

Thanks!

Thanks! Very helpful

Thanks!!!

Great! Thank you very much!

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 commented May 19, 2016

Thanks for the simple guide!

Brilliant.

ghprod commented May 30, 2016

Thanks :)

Thanks.

ybaras commented Jun 8, 2016 edited

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 ๐Ÿ‘

Thanks for the Gist!

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

Thanks for sharing.

Thanks!

nisevi commented Aug 1, 2016

๐Ÿ‘

milad145 commented Aug 8, 2016

how can i uninstall phantomjs?

adamwlev commented Aug 9, 2016

Thank you!

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

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

Thank you for the gist

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

Good stuff ๐Ÿ‘

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.

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

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.

what about :
sudo apt-get install phantomjs

rista404 commented Dec 2, 2016

Thanks @loretoparisi and @mikesten for the updated script, works great! ๐ŸŽ‰

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

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 :-) ๐Ÿ‘

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

Thanks. Worked for me!

bologer commented Jan 26, 2017 edited

ะ”ะปั ั‚ะตั…, ะบั‚ะพ ะผัƒั‡ะฐะตั‚ัั ัƒัั‚ะฐะฝะพะฒะบะพะน phantomjs 2.x.x ะฝะฐ Ubuntu 14.0 โ€” http://bologer.ru/kak-ustanovitobnovit-phantomjs-v-ubuntu-14-04/

Worked here as well, thanks for a wonderful thread!

Worked perfectly !
Thanks !!

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 commented Apr 14, 2017

very helpful! Thanks ;)

Thanks!

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

npm install -g phantomjs-prebuilt

Perfect! thank a lot!!

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