一、首先配置下载软件配置环境(mac版本)
1.下载并安装node.js
$ brew install node.js
或者去
https://nodejs.org/en/下载
测试:
$ node -v
v8.10.0
2.下载并安装git
$ brew install git
或者去
https://git-scm.com/ 下载
测试:
$ git --version
git version 2.15.1 (Apple Git-101)
3.安装hexo
$ npm install -g hexo-cli
测试:
$ hexo -v
hexo: 3.7.1
hexo-cli: 1.1.0
os: Darwin 17.5.0 darwin x64
http_parser: 2.7.0
node: 8.10.0
v8: 6.2.414.50
uv: 1.19.1
zlib: 1.2.11
ares: 1.10.1-DEV
modules: 57
nghttp2: 1.25.0
openssl: 1.0.2n
icu: 60.1
unicode: 10.0
cldr: 32.0
tz: 2017c
二、搭建本地博客
1.在任意目录下新建一个文件夹(我的文件路径:/Users/liuyuting/yuting)
进入到当前目录下,执行:
$ hexo init
注意:此处会报一些错误和警告信息,我们一个一个来解决
1)首页安装依赖:
$ npm install
2)其次我的还报了文件没有权限:
error An unexpected error occurred:"EACCES: permission denied, mkdir '/Users/liuyuting/Library/Caches/Yarn/v1/npm-hexo-renderer-stylus-0.3.3-c54ea27e1fd8e3c8a9a7a84cfba8ad354122ca7f'".
这里我的解决办法是切换到root用户下,然后修改v1文件的权限为(766),然后在回到/Users/liuyuting/yuting目录下,改完权限记得再切回到刚才的用户。
(mac下切换到root用户命令:sudo -i,然后输入密码回撤即可;修改文件权限命令:chmod 766 v1)
2.执行:
$ hexo generate
$ hexo s
INFO Start processing
INFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
当执行hexo s的时候有可能会出现4000端口被占用的情况,这个时候有两种解决方法:
$ hexo s
FATAL Port 4000 has been used. Try other port instead.
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
第一种是换个端口:
$ hexo server -p 5000
第二种是杀死端口为4000的进程
$ sudo lsof -i tcp:4000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 69650 liuyuting 20u IPv4 0x32b9acc08562a4e3 0t0 TCP *:terabase (LISTEN)
192:yuting liuyuting$ sudo kill -9 69650
192:yuting liuyuting$ hexo s
INFO Start processing
INFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
3.浏览搭建的博客
在浏览器中输入:
http://localhost:4000/
.浏览配置的本地博客
注意:不要在控制台中按Ctrl+C关闭服务,当浏览的时候,不然一直是拒绝访问
三、把本地博客部署到github上
1.首先要有一个gitHub账号,然后gitHub里面配置了ssh
$ ssh-keygen -t rsa -C "xxx@163.com"
查看本机的ssh,并把id_rsa中的内容粘贴到github中:
$ cd .ssh
192:.ssh liuyuting$ ls -a -l
total 24
drwx------ 5 liuyuting staff 160 Apr 4 11:39 .
drwxr-xr-x+ 66 liuyuting staff 2112 Jul 10 21:42 ..
-rw------- 1 liuyuting staff 1675 Jul 10 22:05 id_rsa
-rw-r--r-- 1 liuyuting staff 401 Jul 10 22:05 id_rsa.pub
-rw-r--r-- 1 liuyuting staff 1034 Jul 10 22:00 known_hosts
192:.ssh liuyuting$ cat id_rsa.pub
2.配置全局的git:
$ git config --global user.name "你的github用户名"
$ git config --global user.email "你的github注册邮箱" "
3.还需要安装一个插件:
$ npm install hexo-deployer-git --save
4.在github上新建一个仓库
仓库的名称一定是:userName+github.io
5.配置_config.yml文件
在文件最后面添加(注意冒号后面一定要加一个空格):
deploy:
type: git
repo: git@github.com:rainyliu/rainyliu.github.io.git(这里是你的github仓库的地址)
branch: master
6.在terminal中执行:
$ hexo clean
$ hexo d -g
......
INFO Deploy done: git
这里差不多就可以了,然后在浏览器中输入https://userName.github.io,(这里的userName是你的gitHub用户名),我的是
https://rainyliu.github.io