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