title: 安裝hexo
date: 2016-04-23 15:54:25
categories: blog
tags: [hexo,github]
本文在查看網(wǎng)上各位網(wǎng)友的搭建情況下,編寫(xiě).更多作為補(bǔ)充功能.
本文環(huán)境: Windows 7
安裝Git
注: 聽(tīng)說(shuō)新版本可能存在bug,所以盡可能安裝舊版本.
安裝Node.js
重啟電腦
盡量在安裝完Node之后重啟電腦,否則后面可能會(huì)出現(xiàn)比較麻煩的問(wèn)題.
安裝hexo
鼠標(biāo)右鍵任意地方,選擇Git Bash,使用以下命令安裝hexo
$ hexo install hexo-cli -g
如果這里出現(xiàn)WARN并沒(méi)有關(guān)系.
使用以下命令,查看安裝是否成功:
$ hexo v
如果安裝成功,你就會(huì)看到各種版本信息:
hexo-cli: 1.0.1
os: Windows_NT 6.1.7601 win32 x64
http_parser: 2.5.2
node: 4.4.3
v8: 4.5.103.35
uv: 1.8.0
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 56.1
modules: 46
openssl: 1.0.2g
如果不成功.那么你應(yīng)該檢查你以上操作有沒(méi)有什么問(wèn)題.多留意提示才是關(guān)鍵.
創(chuàng)建文件夾 E:\hexo, 并在這個(gè)文件夾內(nèi)右鍵Git bash Here,執(zhí)行命令:
$ hexo init
然后安裝依賴(lài)包:
$ hexo install
查看hexo文件夾帶來(lái)什么:
$ hexo g
$ hexo s
用瀏覽器訪(fǎng)問(wèn) (http://localhost:4000/ ) 此時(shí),你應(yīng)該看到了一個(gè)漂亮的本地博客.
注冊(cè)Github賬號(hào)
極其簡(jiǎn)單.我不寫(xiě)了. 假設(shè)這里創(chuàng)建的信息:
用戶(hù)名: xiaoming
注冊(cè)郵箱: xiaoming@163.com
創(chuàng)建repository
<strong>注意: 這里的repository 名稱(chēng)只能為: xiaoming.github.io
千萬(wàn)要注意!這里的名稱(chēng),是不能使用一個(gè)隨便的repository!!
部署本地文件到Github
編輯E:\hexo下的_config.yml文件
在文件的最后加入代碼:
deploy:
type: git
repository: https://github.com/xiaoming/xiaoming.github.io.git
branch: master
執(zhí)行以下命令:
$ hexo g
$ hexo d
出現(xiàn)錯(cuò)誤:
<strong>ERROR Deployer not found : git
執(zhí)行命令:
$ npm install hexo-deployer-git --save
$ hexo g
$ hexo d
接下來(lái)又是一個(gè)錯(cuò)誤, 這個(gè)錯(cuò)誤是:
INFO Deploying: git
INFO Setting up Git deployment...
Initialized empty Git repository in E:/hexo/.deploy_git/.git/
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'dan@dan-PC.(none)')
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/do
cs/troubleshooting.html
Error:
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'XXX@XXX-PC.(none)')
at ChildProcess.<anonymous> (E:\hexo\node_modules\hexo-deployer-git\node_mod
ules\hexo-util\lib\spawn.js:37:17)
at emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at ChildProcess.cp.emit (E:\hexo\node_modules\hexo-deployer-git\node_modules
\hexo-util\node_modules\cross-spawn\node_modules\cross-spawn-async\lib\enoent.js
:37:29)
at maybeClose (internal/child_process.js:827:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
FATAL
這個(gè)錯(cuò)誤是因?yàn)楫?dāng)前本地的Git還沒(méi)配置用戶(hù)信息, 所以執(zhí)行以下命令:
$ git config --global user.email "xiaoming@163.com"
$ git config --global user.name "xiaoming"
$ hexo d
此時(shí),會(huì)要求輸入用戶(hù)名, 你就輸入你的用戶(hù)名: xiaoming
接著要求輸入密碼, 你就入密碼. 密碼輸入期間不會(huì)看到任何字符.然后直接回車(chē)即可.
結(jié)束
至此, 博客創(chuàng)建完成. 登陸網(wǎng)站: xiaoming.github.io 就可以看到啦!
常用命令備注:
$ hexo g #完整命令為hexo generate,用于生成靜態(tài)文件
$ hexo s #完整命令為hexo server,用于啟動(dòng)服務(wù)器,主要用來(lái)本地預(yù)覽
$ hexo d #完整命令為hexo deploy,用于將本地文件發(fā)布到github上
$ hexo n #完整命令為hexo new,用于新建一篇文章