整个过程建议进入root用户操作,以避免一些问题
通过apt-get install npm
安装的npm是0.1x版本的,太过旧,而且在root下无法启动,提示找不到npm
于是可以通过curl工具可安装最新版:
sudo curl -L https://npmjs.org/install.sh | sh
方法来自node.js官网
配置淘宝的源为npm的默认源
`sudo npm config set registry https://registry.npm.taobao.org`
安装markdown-pdf,输入
sudo npm install markdown-pdf
输出为
/usr/local/bin/markdown-pdf -> /usr/local/lib/node_modules/markdown-pdf/bin/markdown-pdf
> phantomjs-prebuilt@2.1.14 install /usr/local/lib/node_modules/markdown-pdf/node_modules/phantomjs-prebuilt
> node install.js
PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...
提示找不到PhantomJS
,要安装,但下载速度很慢,无法下载完成,最后提示错误,错误如下:
Receiving...
[----------------------------------------] 1%
Error making request.
Error: read ECONNRESET
at exports._errnoException (util.js:1034:11)
at TLSWrap.onread (net.js:584:26)
Please report this full log at https://github.com/Medium/phantomjs
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! phantomjs-prebuilt@2.1.14 install: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the phantomjs-prebuilt@2.1.14 install script 'node install.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the phantomjs-prebuilt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node install.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs phantomjs-prebuilt
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls phantomjs-prebuilt
npm ERR! There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-03-29T01_42_35_693Z-debug.log
因为是定位到github去下载的,而不是通过源的资源,所以换成国内源也没用,可直接复制下载地址
https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
到下载工具,下载完后放到目标目录
/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
再执行
sudo npm install phantomjs-prebuilt
便可成功安装phantomjs,接着再执行
sudo npm install markdown-pdf
便可成功
如仍无法解决,可使用cnpm,参考我的另一篇博文sudo npm install错误
可解决一大部分的安装问题