phantomjs: command not found

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


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.


Mac PATH suggested setup:

  1. Open Terminal.
  2. Type vi ~/.bash_profile and hit enter (this opens or creates your bash_profile where you can customize Terminal commands).
  3. Press 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.
  4. Press esc to exit insert/edit mode then type :x and hit enter to save the file.
  5. Quit and re-open Terminal.
  6. Type phantomjs and hit enter. If you see the prompt phantomjs> then you're all set.
  7. Type phantom.exit() to end the PhantomJS program.
  8. Now you can navigate to any folder and run PhantomJS by simply typing phantomjs. This is helpful when saving screenshots because the images will be saved inside the folder that's active in your Terminal.

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.