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 packagefontconfig
orlibfontconfig
, 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
如果你看到當前版本號,即表示正常工作了。