注意是centos环境下遇到的各种问题
标题中的错误是PhantomJS在全局环境变量中没有找到,所以npm install
的过程中会自动安装。但过程比较曲折…
我的成功解决办法
npm install phantomjs@2.1.1 --unsafe-perm
以上,之所以加--unsafe-perm
是因为phantomjs安装过程会创建软连接到全局变量,而phantormjs是以spawn子进程的方式创建,没有这个flag,即便使用root用户安装,同样会提示Error: EACCES: permission denied
以下是其他可能的错误:
cmd: 'tar jxf /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2' } Error: Command failed: tar jxf /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
tar (child): bzip2: Cannot exec: No such file or director
以上需要安装bz2
此外,github issue上看到了其他的解决办法,但我试并没有成功
cd /usr/local/share
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo tar xjf phantomjs-2.1.1-linux-x86_64.tar.bz2
sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs
sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
sudo ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs