在Mac上安装PhantomJS

问题描述 投票:26回答:6

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

我做了以下事情:

npm install phantomjs

然后我做了:

npm install phantomjs-prebuilt

这两个都出现在我的node_modules中。但是,当我尝试运行phantomjs --versionI得到

   -bash: phantomjs: command not found

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

Fatal: [Errno 2] No such file or directory; did you install phantomjs?

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

installation phantomjs casperjs
6个回答
40
投票

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

brew tap homebrew/cask
brew cask install phantomjs

26
投票
  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

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

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

cd $HOME
curl -O https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-macosx.zip

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

export PATH=$HOME/phantomjs-2.1.1-macosx/bin:$PATH

然后运行:

source ~/.bash_profile

16
投票

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

brew tap homebrew/cask
brew cask install phantomjs

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


2
投票

你不应该在全球安装phantomjs吗?

npm install -g phantomjs

由于您在本地安装它,命令 -

phantomjs -v

不会到处工作。

您可以在此处检查本地安装和全局安装之间的区别:https://docs.npmjs.com/cli/install


0
投票

经过大量的挖掘后,我发现了High-Sierra旧版本的phantomjs(<2.0)would not work

此外,通过phantomjs download page的zip文件是一个错误的。

如果您需要一个新的幻像,只需转到this页面并下载phantomjs 2.1.1(或更高版本)。

© www.soinside.com 2019 - 2024. All rights reserved.