I followed these instructions (except for copying the executable to my PATH because I cannot seem to find it and it does not seem necessary). Then I made a file called image
The PATH
really is the important part. You can skip it, however, if you specify the absolute path. Try something like this:
/path/to/phantomjs render_image.js
...but that can get tiring. For a quick way to add it to your PATH
, from the directory of the phantomjs
executable, symbolically link it into /usr/local/bin
:
sudo ln -s /path/to/phantomjs /usr/local/bin/
/usr/local/bin
is likely on your PATH
.
Whatever command is just a executable file. To be accessible by type its name directly, you have to put it into a path that system will look for that file directly.
For linux/OSX, it's /usr/bin or /usr/local/bin. Which really works? Well, it depends...
So what worked for me is extract the 'phantomjs.tar.bz2' source file to somewhere and copy the executable file to /usr/local/bin like this:
cp path-of-extracted-phantomjs/bin/phantomjs /usr/local/bin
add this line to this file /home/optiman2/.bashrc
PATH=/home/optiman2/phantomjs/bin:$PATH
this worked for me.
and remember to use this command, before test phantomjs: source .bashrc
FYI to Windows users upgrading to version 2.0.0 - the executable has moved. In addition to changing your PATH environment variable to 2.0.0, you'll need to add \bin
to the end of the PATH that you had for the 1.x.x.
Mac PATH suggested setup:
vi ~/.bash_profile
and hit enter (this opens or creates your bash_profile where you can customize Terminal commands).i
to enter insert/edit mode then type alias phantomjs='~/PATH/TO/phantomjs'
and be sure to replace ~/PATH/TO/phantomjs
with something like ~/Documents/PhantomJS/bin/phantomsj
or wherever the file exists on your machine.esc
to exit insert/edit mode then type :x
and hit enter to save the file.phantomjs
and hit enter. If you see the prompt phantomjs>
then you're all set.phantom.exit()
to end the PhantomJS program.phantomjs
. This is helpful when saving screenshots because the images will be saved inside the folder that's active in your Terminal.