无法在Linux上执行PhantomJS

时间:2014-12-11 17:52:02

标签: linux bash ubuntu-12.04 phantomjs

一直试图在Ubuntu 12.04 VM上安装最新版本(1.9.8)的phantomjs但没有成功。 这是我到目前为止所做的:

  1. 要删除旧版本,请执行

    sudo apt-get remove phantomjs
    
  2. 要删除旧的符号链接,执行

    rm -r /.../phantomjs
    
  3. 将phantomjs-1.9.8-linux-x86_64.tar.bz2.2下载到/ usr / local / share目录并解压缩:

    sudo wget . . ..tar.bz2
    sudo tar xjf phantomjs-1.9.8-linux-x86_64.tar.bz2
    
  4. 为/ usr / local / share /,/ usr / local / bin /和/ usr / bin

    创建了新的符号链接
    sudo ln -s /usr/local/share/phantomjs-1.9.8-linux-x86_64/bin/phantomjs  /usr/. . ./phantomjs
    
  5. 选中版本:

    phantomjs --version 
    
  6. 这是返回的消息:

    -bash: /usr/local/bin/phantomjs: cannot execute binary file
    

    有人可以解释为什么会发生这种情况以及如何解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

有人建议使用npm来安装:

sudo apt-get install nodejs npm 

有问题:

. . . 
nodejs is already the newest version. 
Some packages could not be installed. 
This may mean that you have requested an impossible situation or 
if you are using the unstable distribution that some required packages have not yet been created
or been moved out of Incoming. The following information may help resolve the situation:
The following packages have unmet dependencies:
 nodejs : Conflicts: npm
E: Unable to correct problems, you have held broken packages.

被告知简单apt-get install nodejs也安装npm,所以尝试了,然后是

sudo npm -g install phantomjs 

最后:

... 
Done. Phantomjs binary available at /usr/lib/node_modules/phantomjs/lib/phantom/bin/phantomjs phantomjs@1.9.12
 /usr/lib/node_modules/phantomjs 
├── which@1.0.8
├── progress@1.1.8
├── rimraf@2.2.8
├── ncp@1.0.1 ├── kew@0.4.0
├── adm-zip@0.4.4
├── request-progress@0.3.1 (throttleit@0.0.2)
├── mkdirp@0.5.0 (minimist@0.0.8)
├── npmconf@2.0.9 (uid-number@0.0.5, inherits@2.0.1, osenv@0.1.0, ini@1.3.2, once@1.3.1, 
      config-chain@1.1.8, semver@4.1.0, nopt@3.0.1) 
└── request@2.42.0 (caseless@0.6.0, json-stringify-safe@5.0.0, aws-sign2@0.5.0, 
forever-agent@0.5.2, stringstream@0.0.4, oauth-sign@0.4.0, tunnel-agent@0.4.0, qs@1.2.2, 
node-uuid@1.4.2, mime-types@1.0.2, http-signature@0.10.0, form-data@0.1.4, bl@0.9.3, hawk@1.1.1, 
tough-cookie@0.12.1) 

检查版本:

sudo phantomjs --version 
1.9.8 

作为安装和工作的最终证明,重新运行以前失败的黄瓜测试(因为幻影失踪而无法通过),所有依赖于幻影的黄瓜测试现在都通过了

答案 1 :(得分:0)

我遇到了同样的问题,然后我按照用法使用

<强>步骤1

首先转到http://phantomjs.org/download.html 并下载与32位或64位匹配的系统版本的zip文件

<强>步骤-2

提取已下载的zip文件

<强>步骤-3

打开终端然后到达解压文件夹,然后它将有bin文件夹

<强>步骤4

运行以下命令

 > sudo cp phantomjs /bin

之后运行phantomjs命令

> phantomjs -v
2.1.1