Recently I’m getting more and more enthusiastic about using CasperJS as a scraper, but also for automating some web stuff I’m doing on a regular basis (downloading binaries, filling forms, etc.). I’m not explaining CasperJS and it’s uses here, but will quote the official website to tell what CasperJS is all about:
Quite a powerfull tool, so let’s install it!
CasperJS has some prerequisites, you must have PhantomJS 1.8.1 or greater and Python 2.6 or greater installed. Python is easily installed by using the package manager (for Debian and Ubuntu
apt, other distributions might use another package manager), but the latest PhantomJS isn’t always in the repositories.
So we need to install PhantomJS first, luckily it’s pretty easy to install PhantomJS by following these steps:
- Login to the console and navigate to
- Head to http://phantomjs.org/download.html. Under the header “Linux” you are able to find the download url for the packages
- Download the package using wget:
sudo wget https://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-x86_64.tar.bz2
sudomust be used because of the permissions of the
- Because we need to organize this package ourselfs, I decided to extract the contents of the tar file to a separate directory for each version:
sudo tar -xvf phantomjs-1.9.1-linux-x86_64.tar.bz2
/usr/local/sharethere will be a folder called
phantomjs-1.9.1-linux-x86_64, because I want to organize it, i’m moving it to a little bit nicer named folder:
sudo mv phantomjs-1.9.1-linux-x86_64 phantomjs-1.9.1
- The next step is making the phantomjs binary widely available on the system. I could add the directory to the environment path, but with every version I would need to change it and for every other manually installed package I will have to edit the environment path again. In my opinion, there’s a better way for organizing this.
First we make a symlink called
phantomjsand point it to the package:
sudo ln -s /usr/local/share/phantomjs-1.9.1/ /usr/local/share/phantomjs
- Then we need to make a symlink in
/usr/local/bin(which is in the environment path already) to the binary in
sudo ln -s /usr/local/share/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
- The latest PhantomJS should now be installed. Test that by using:
Which should give you the version number, in this case
PhantomJS is now installed.
When a new version is released, we only have to change the
/usr/local/share/phantomjs symlink to point to the new version folder and the whole system will use the new phantomjs version. If the old version is required, we still can use that one by pointing the command to the specific version (for example version 1.8.1):
PhantomJS is installed, so now it’s time to install CasperJS.
Installing CasperJS is mostly the same as installing PhantomJS, so I won’t explain it as extensive as I did above with installing PhantomJS. If you want to know why I did things, see the PhantomJS installation instructions.
- Login to the console and navigate to
- Head to the CasperJS download page for the download url
- Download the latest archive:
sudo wget -O casperjs.tar https://github.com/n1k0/casperjs/tarball/1.0.0
- Extract the archive and rename the folder (folder name might be different, so you might want to check that first):
sudo tar -xvf casperjs.tar sudo mv n1k0-casperjs-0628688 casperjs-0628688
- Create a symlink to the current version:
sudo ln -s /usr/local/share/casperjs-0628688/ /usr/local/share/casperjs
- Make the casperjs binary available system wide:
sudo ln -s /usr/local/share/casperjs/bin/casperjs /usr/local/bin/casperjs
- Test if it’s working by using:
If the last command shows you a version number, then CasperJS is installed successfully. When a new version of CasperJS arrives, just change the symlink in
/usr/local/share/casperjs to point to the new version.
For more information about symlinks and adjusting symlinks, see: symlink cheatsheet