Mac上搭建基于GitHub的Hexo博客(一)
2017-09-07 本文已影响0人
KODIE
今天来谈谈如何在Mac上搭建基于GitHub的Hexo博客
导读
安装
根据上面文章里面提到的安装步骤我们按着来:
第一步:安装Node.js
用处:用来生成静态页面。
官网:Node.js官网
PS: 上文中建议下载v5.5.0 Stable 一路安装,我此处是下载了最新的v8.4.0


第二步:安装Git
用处:用来将本地Hexo内容提交到Github上
安装:Xcode自带Git,这里不再赘述。如果没有Xcode可以参考Hexo官网上的安装方法。
第三步:安装Hexo
这步骤是比较重要的,我就卡在这里了
官网命令:
$ npm install -g hexo-cli

开篇文中命令是:
$ sudo npm install -g hexo
在此处我都试过了不行,报错:

满屏的报错我也是醉了,看到这个很是心碎,具体报错内容如下:
> hexo-util@0.6.1 build:highlight /usr/local/lib/node_modules/hexo/node_modules/hexo-util
> node scripts/build_highlight_alias.js > highlight_alias.json
sh: highlight_alias.json: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hexo-util@0.6.1 build:highlight: `node scripts/build_highlight_alias.js > highlight_alias.json`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hexo-util@0.6.1 build:highlight script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
┌──────────────────────────────────────────────────────────┐
│ npm update check failed │
│ Try running with sudo or get access │
│ to the local update config store via │
│ sudo chown -R $USER:$(id -gn $USER) /Users/KODIE/.config │
└──────────────────────────────────────────────────────────┘
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: dtrace-provider@0.8.5 (node_modules/hexo/node_modules/dtrace-provider):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: dtrace-provider@0.8.5 install: `node scripts/install.js`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hexo-util@0.6.1 postinstall: `npm run build:highlight`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hexo-util@0.6.1 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/KODIE/.npm/_logs/2017-09-07T01_54_22_329Z-debug.log
我尝试用官网的提示说已经存在了hexo,那我要删除,然后中间小方框提示的东西是没有用的,有用的地方可能就是告诉我们用这个命令的时候需要用到sudo,但是现在是我们之前已经安装了一次了存在相应的目录,现在用官网的命令又安了一遍,目录已经存在无法安装:

具体报错:
npm ERR! path /usr/local/bin/hexo
npm ERR! code EEXIST
npm ERR! Refusing to delete /usr/local/bin/hexo: ../lib/node_modules/hexo/bin/hexo symlink target is not controlled by npm /usr/local/bin
npm ERR! File exists: /usr/local/bin/hexo
npm ERR! Move it away, and try again.
┌──────────────────────────────────────────────────────────┐
│ npm update check failed │
│ Try running with sudo or get access │
│ to the local update config store via │
│ sudo chown -R $USER:$(id -gn $USER) /Users/KODIE/.config │
└──────────────────────────────────────────────────────────┘
因为已经存在了,所以我们可能会想说不定安装成功了呢,那测试一下hexo:

那还是老老实实删除掉这个文件吧:
$ cd /usr/local/bin
$ sudo rm ./hexo
$ ls

那不行的话只有谷歌了,请查阅此文:npm install -g hexo-cli failed #2695
文中提到一串命令:
$ npm config set user 0
$ npm config set unsafe-perm true
$ npm install -g hexo-cli

尝试之后问题得到解决,但是有一个问题一定要先把hexo这个文件给删除掉,才能安装成功,我在第三条命令前加了sudo,我执行的命令如下:
$ npm config set user 0
$ npm config set unsafe-perm true
$ sudo npm install -g hexo-cli
后面的就跟着导读文章去做就好了,以上!!!
