【问题标题】:How to update phantomjs 1.9.8 to phantomjs 2.1.1 on ubuntu?如何在 ubuntu 上将 phantomjs 1.9.8 更新为 phantomjs 2.1.1?
【发布时间】:2020-01-29 03:16:13
【问题描述】:

我无法在我的 ubuntu 16.04 上重新安装 phantomjs 1.9.8 到 2.1.1 版本 请帮忙。 1.9.8 在我编写自旋函数时给我一个错误,在文档中看到这个问题我可以通过重新安装来解决。

【问题讨论】:

    标签: ubuntu phantomjs updates reinstall


    【解决方案1】:

    我刚刚通过以下步骤在 ubuntu 16.04 中安装了 phantomjs 2.1.1,经过一番谷歌搜索后发现:

    sudo apt-get install nodejs
    sudo apt-get install nodejs-legacy
    sudo apt-get install npm
    sudo npm -g install phantomjs-prebuilt
    

    【讨论】:

    • 由于 PhantomJS 与 node.js 或 npm 无关(仅为方便而安装),这为与生态系统无关的单个二进制文件安装了整个生态系统。
    • 确实如此。 npm 需要 nodejs(和 nodejs-legacy)才能成功安装 phantomjs。我遵循的步骤是在 python 中与 selenium 一起使用。完成后总是可以卸载 npm。这只是让 PhantomJS 驱动程序与 selenium 一起工作的一种非常快速的方法。
    【解决方案2】:

    如果我正在开发,我会这样做。这些包的版本是 nodejs 而不是 ubuntu:

    使用nvmhttps://github.com/creationix/nvm

    touch ~/.profile
    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.7/install.sh | bash
    
    source ~/.profile
    # node 6x
    nvm install 6.5.0 
    npm install phantomjs@2.1.1
    
    # node 4x
    nvm install 4.5.0
    nvm use 4.5.0
    npm install phantomjs@1.9.19
    
    # node 0.12x
    nvm install 0.12
    npm show phantomjs@* version
    npm install phantomjs@1.9.8
    

    也许我们正在 0.10, 0.12, 4.X, iojs4.x, 6.X, etc 上开发,现在我们可以选择任何版本的 phantomjs:

    jmunsch@ubuntu:~$ npm show phantomjs@* version
    phantomjs@0.0.1 '0.0.1'
    phantomjs@0.0.2 '0.0.2'
    phantomjs@0.0.3 '0.0.3'
    phantomjs@0.0.4 '0.0.4'
    phantomjs@0.0.5 '0.0.5'
    phantomjs@0.0.6 '0.0.6'
    phantomjs@0.0.7 '0.0.7'
    phantomjs@0.0.8 '0.0.8'
    phantomjs@0.0.9 '0.0.9'
    phantomjs@0.1.0 '0.1.0'
    phantomjs@0.1.1 '0.1.1'
    phantomjs@0.2.0 '0.2.0'
    phantomjs@0.2.1 '0.2.1'
    phantomjs@0.2.2 '0.2.2'
    phantomjs@0.2.3 '0.2.3'
    phantomjs@0.2.4 '0.2.4'
    phantomjs@0.2.5 '0.2.5'
    phantomjs@0.2.6 '0.2.6'
    phantomjs@1.9.8 '1.9.8'
    phantomjs@1.9.9 '1.9.9'
    phantomjs@1.9.10 '1.9.10'
    phantomjs@1.9.11 '1.9.11'
    phantomjs@1.9.12 '1.9.12'
    phantomjs@1.9.13 '1.9.13'
    phantomjs@1.9.15 '1.9.15'
    phantomjs@1.9.16 '1.9.16'
    phantomjs@1.9.17 '1.9.17'
    phantomjs@1.9.18 '1.9.18'
    phantomjs@1.9.19 '1.9.19'
    phantomjs@2.1.1 '2.1.1'
    phantomjs@2.1.2 '2.1.2'
    phantomjs@2.1.3 '2.1.3'
    phantomjs@1.9.20 '1.9.20'
    phantomjs@2.1.7 '2.1.7'
    

    系统范围的部署场景等

    这里是如何使用压缩包

    export PHANTOM_JS_VERSION=2.1.1
    wget "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2"
    tar xvfj "./phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2"
    ln -sf "./phantomjs-$PHANTOM_JS_VERSION-linux-x86_64/bin/phantomjs" "/usr/bin"
    

    在 ubuntu 14.04 上测试,可能将文件夹移动到 ./ 以外的其他地方

    16.04 更新:

    wget 可能有效也可能无效,请参阅:https://github.com/Medium/phantomjs/issues/161

    # install dependencies
    sudo apt-get install libfontconfig
    # extract the tar file
    tar xvfj "./phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2"
    # use full path
    ln -sf "$(pwd)/phantomjs-$PHANTOM_JS_VERSION-linux-x86_64/bin/phantomjs" "/usr/bin"
    

    错误

    phantomjs:加载共享库时出错:libfontconfig.so.1:无法打开共享对象文件:没有这样的文件或目录

    试试:

     sudo apt-get install libfontconfig
    

    【讨论】:

    • @3zzy 你是对的,更新看起来像一个依赖问题,链接到相对路径可能是一个问题。同样出于某种原因wget 无法正常工作,所以我将scp tar 球转移到机器上。添加了具有相同 403 访问被拒绝错误的 github 问题。
    【解决方案3】:

    所以,jmunsch 的回答对我有用,但只是为了提供一个清晰且最小的配方:

    export PHANTOM_JS_VERSION=2.1.1
    
    sudo apt-get install libfontconfig
    
    wget "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2"
    
    tar xvfj "./phantomjs-$PHANTOM_JS_VERSION-linux-x86_64.tar.bz2"
    
    ln -sf "$(pwd)/phantomjs-$PHANTOM_JS_VERSION-linux-x86_64/bin/phantomjs" "/usr/bin"
    

    由于 /usr/bin,最后一行需要 sudo,但您可以将符号链接放在任何地方...

    【讨论】:

      【解决方案4】:

      对于像我一样安装有问题的人

      比你想象的要容易...

      • 我卸载phantomjs:从ubuntu sudo apt-get remove phantomjs 中删除phantomjs 或删除/node_modules/phantomjs 的npm 文件夹,它将在/,也许你需要删除ln phantomjs 在/usr/bin 或@987654326 中的链接@它的名字是phantomjs

      例子

      //use this if you installed with apt-get
      sudo apt-get remove phantomjs    *remove the phantomjs
      rm /usr/bin/phantomjs            *use this if the link didn't remove.
      
      //use this if you installed from npm: like this: npm install phantomjs
      rm -R /node_modules/phantomjs    *note: it will be in other folder, search it.
      
      • 从 npm 安装 phantomjs:npm install phantomjs/ 目录,npm 将其安装在文件夹 /node_module/phantomjs

      例子

      cd /;
      npm install phantomjs
      
      • 测试 bin 文件

      例子

      //check version of phantomjs
      /node_modules/phantomjs/bin/phantomjs -v
      /node_modules/phantomjs/bin/phantomjs test.js
      
      • 将文件 bin 链接到 /usr/bin:

      例子

      ln -sf /node_modules/phantomjs/bin/phantomjs /usr/bin/phantomjs

      • 检查它的版本,看看它是否正常
        phantomjs -v 在我的情况下是2.1.1

      【讨论】:

        【解决方案5】:

        phantomjs 2.1.1 目前与 16.04 (https://launchpad.net/ubuntu/xenial/+source/phantomjs) 捆绑在一起,因此您应该能够将其作为系统包安装/升级。

        更新:此答案的存在是为了提供信息,但现在不建议使用系统包版本,原因如下:https://bugs.launchpad.net/ubuntu/+source/phantomjs/+bug/1605628 这与文件上传问题有关已在上游修复,但修复的性质使其无法作为系统包工作。

        目前最好的选择是使用来自https://bitbucket.org/ariya/phantomjs/download的预构建二进制文件

        【讨论】:

          【解决方案6】:

          由于批准的步骤对我不起作用,我正在分享我找到的解决方案。

          # Install phantomJS
          export PHANTOM_JS="phantomjs-2.1.1-linux-x86_64"
          wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
          sudo tar xvjf $PHANTOM_JS.tar.bz2
          
          sudo mv $PHANTOM_JS /usr/local/share
          sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
          
          # Sanity check 
          phantomjs --version
          >>> 2.1.1
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2012-02-05
            • 2016-07-29
            • 1970-01-01
            • 2018-06-18
            • 2017-03-26
            • 2018-11-16
            • 1970-01-01
            相关资源
            最近更新 更多