Installing PhantomJS on OSX for Designers
PhantomJS is a headless webkit-based browser with all kinds of nifty use cases. In it’s simplest form, it’s a javascript-driven web scraper. I’m writing this guide note for any novice users having problems installing it on OS X.
Ariya Hidayat wrote instructions on installing PhantomJS on OSX, but glosses over one of the most important steps that is assumed knowledge for competent devs. He has made it as simple as possible to download and extract the binary source as an executable, but as new Mac/Unix user I didn’t understand what was meant by references to changing the PATH.
In order to run phantomjs as a command (and therefore pass another file to it), the folder phantomjs is stored in needs to be indexed via PATHs. This means you’ll be able to: phantomjs helloworld.js. Prior to adding it the PATH reference, phantomjs would not be recognised as a command - or if run from inside the executable, it would result in parse error.
So, all you need to do is add the directory to the PATH variable and you’ll be good to go.
Again:
- Download and extract OSX static build
- Add phantomjs directory to PATH variable
- You’re good to go.
This took me way longer to grasp than necessary, so hopefully this helps you avoid making the mistakes I did.