Skip to content

Instantly share code, notes, and snippets.

@julionc
Last active February 21, 2024 11:01
Show Gist options
  • Save julionc/7476620 to your computer and use it in GitHub Desktop.
Save julionc/7476620 to your computer and use it in GitHub Desktop.
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
@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

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

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

@pdelteil
Copy link

Works correctly in Ubuntu 20.10.

@mateusleon
Copy link

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

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

Thank youuu!

Copy link

ghost commented Jun 14, 2022

useful guide,
although I did ended up migrating to https://github.com/puppeteer/puppeteer .

@Mgavahi
Copy link

Mgavahi commented Aug 17, 2022

Hi, I installed phantomjs in ubuntu 22.04 and when use it in Rstudio for my code get Auto configuration failed error. i readed all comment and use all of them for resolving this error but don't worked!!!

@Neo-Desktop
Copy link

here's a slightly better and fully automated version of that script in the original post and adds the automatic version downloading snippet from here

#!/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_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)
PHANTOM_VERSION=${PHANTOM_JS_LATEST%-*-*.*.*}
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/bin

@ecc256
Copy link

ecc256 commented Sep 1, 2022

@Neo-Desktop

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

Ouch...
How does it work for "arm64" architecture?

@ecc256
Copy link

ecc256 commented Sep 1, 2022

Anybody have luck with ubuntu 22.04/arm64?

@mauro-miatello
Copy link

Anybody have luck with ubuntu 22.04/arm64?

nope, I've same problem

@antonellosalis
Copy link

It is very strange for me.
I installed, the phantomjes --version shows 2.1.1 but it have no effect...still the message appears on my shiny app.

@tpongo-afk
Copy link

To solve the Auto configuration failed error see this issue
Type this in the terminal before executing phantomjs: export OPENSSL_CONF=/etc/ssl

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