在Mac上安装PhantomJS

jbl*_*ley 33 installation phantomjs casperjs

我正在尝试在我的Mac(Yosemite)上安装PhantomJS.

我做了以下事情:

npm install phantomjs
Run Code Online (Sandbox Code Playgroud)

然后我做了:

npm install phantomjs-prebuilt
Run Code Online (Sandbox Code Playgroud)

这两个都出现在我的node_modules中.但是当我试着奔跑时,phantomjs --version我得到了

   -bash: phantomjs: command not found
Run Code Online (Sandbox Code Playgroud)

还尝试从下载网站安装二进制文件,但没有.我错过了什么?最终目标是使用casperjs,但目前casper正在询问

Fatal: [Errno 2] No such file or directory; did you install phantomjs?
Run Code Online (Sandbox Code Playgroud)

我以为我做了......?

Vla*_*dtn 47

如果您使用的是Homebrew,您可以输入:

brew tap homebrew/cask
brew cask install phantomjs
Run Code Online (Sandbox Code Playgroud)

  • 它从homebrew/core迁移到homebrew/cask.你可以通过运行:brew tap homebrew/cask再次访问它然后你可以通过运行来安装它:brew cask install phantomjs (8认同)
  • 它提醒我使用“brew install --cask phantomjs”。 (3认同)

小智 29

  1. http://phantomjs.org/download.html下载phantomjs最新版本(例如:phantomjs-2.1.1-macosx.zip)
  2. 将其解压缩到某个路径(例如:〜/ Desktop/phantomjs-2.1.1-macosx)
  3. 在终端上运行此命令 - sudo ln -n~/Desktop/phantomjs-2.1.1-macosx/bin/phantomjs/usr/local/bin /
  4. 通过命令从终端启动phantomjs:phantomjs
  5. 通过命令检查phantomjs版本:phantomjs -v
  6. 通过命令检查phantomjs路径:哪个phantomjs

  • 你救了我。 (2认同)

God*_*ude 17

您需要将phantomjs二进制文件添加到PATH中.您可以通过修改环境变量或通过将二进制文件符号化来实现此目的/usr/local/bin

例如,如果要对二进制文件进行符号链接:

cd $HOME
curl -O https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-macosx.zip
ln -s $HOME/phantomjs-2.1.1-macosx/bin/phantomjs /usr/bin/phantomjs
Run Code Online (Sandbox Code Playgroud)

或者如果要修改PATH环境变量:

cd $HOME
curl -O https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-macosx.zip
Run Code Online (Sandbox Code Playgroud)

并将此行添加到此文件~/.bash_profile::

export PATH=$HOME/phantomjs-2.1.1-macosx/bin:$PATH
Run Code Online (Sandbox Code Playgroud)

然后运行:

source ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)

  • 他们为什么不做一个合适的安装人员? (6认同)

cgn*_*utt 16

接受的答案已过时.在Mac上,使用Homebrew,键入:

brew tap homebrew/cask
brew cask install phantomjs
Run Code Online (Sandbox Code Playgroud)

某些MacOS版本可能不需要第一步.