Linux下安装Phantomjs

1. 安装linux系统的软件包

先来看一下官方网站的提示:

Note: For this static build, the binary is self-contained. There is no requirement to install Qt, WebKit, or any other libraries. It however still relies on Fontconfig (the package fontconfig or libfontconfig, depending on the distribution). The system must have GLIBCXX_3.4.9 and GLIBC_2.7.
上面是官方网站的说明:phantomjs不依赖过多的包,但是根据linux的版本不同,可能依赖fontconfig或者libfontconfig
Centos系列版本的linux依赖fontconfig这个软件包,Ubuntu系列版本的linux依赖libfontconfig这个软件包。

Centos的依赖包安装命令:

sudo yum install gcc gcc-c++ make git openssl-devel freetype-devel fontconfig-devel 

其中主要是fontconfig-devel,只要你的linux系统不是裸系统,其他的都应该有了。

Ubuntu的依赖包安装命令:

sudo apt-get install build-essential chrpath git-core libssl-dev libfontconfig1-dev libxft-dev

其中主要是libfontconfig1-dev

2. 下载安装phantomjs

下载链接:wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2

wget后面的连接是从官方网站获得的,根据自己的os的型号和位数找到对应的下载地址。

解压文件:

tar -xvf phantomjs-1.9.7-linux-x86_64.tar.bz2

将程序移到一个合适的位置:

sudo mv phantomjs-1.9.7-linux-x86_64 /usr/local/src/phantomjs

创建软链接到环境变量中。这样可以直接在shell中使用phantomjs命令:

sudo ln -sf /usr/local/src/phantomjs/bin/phantomjs /usr/local/bin/phantomjs

其中的参数s表示为软链接,参数f表示强制。

检查是否正常工作:

phantomjs –version

如果你看到当前版本号,即表示正常工作了。

3. 参考链接

  1. http://www.lao8.org/article_1547/phantomjs_centos_linux
  2. http://ju.outofmemory.cn/entry/70691
  3. 官方地址:http://phantomjs.org/download.html
posted @ 2017-03-23 21:44  stemon  阅读(7871)  评论(2编辑  收藏  举报