如何在ubuntu上更新phantomjs 1.9.8到phantomjs 2.1.1?

我不能重新安装phantomjs 1.9.8到2.1.1版本在我的Ubuntu 16.04请帮助。 1.9.8给我一个错误,当我写一个旋转函数,在文档中看到这个问题,我可以用reinstlation解决。

我刚刚在ubuntu 16.04中安装了phantomjs 2.1.1,下面是一些Google搜索后发现的步骤:

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

如果我正在开发,我将如何做到这一点。 该软件包版本为nodejs而不是ubuntu:

使用nvm : https : //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' 

系统范围的部署场景等

这里是如何使用tarball

 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 

所以,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" 

最后一行需要sudo,因为/ usr / bin,但是你可以把符号链接放在任何地方…

对于那些有问题要像我一样安装

它比你想象的更容易…

  • 我卸载phantomjs:从ubuntu删除phantomjs sudo apt-get remove phantomjs或删除/node_modules/phantomjs npm文件夹它将在/ ,也许你需要删除在/usr/bin/usr/local/bin/ phantomjs的链接/usr/local/bin/它的名字是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 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

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