English 中文(简体)
phantomjs: command not found
原标题:

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_render.js in my public javascripts directory with

console.log( Hello, world! );
phantom.exit();

inside it, saved it, and ran phantomjs render_image.js in my terminal. However, my terminal does not recognize the command:

-bash: phantomjs: command not found

What have I done wrong?

最佳回答

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.

问题回答

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 in to the end of the PATH that you had for the 1.x.x.

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.

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





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签