Building a blog with Github Pages & Hexo on MacOS

Installation

Install Homebrew

1
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Node.js

1
$ brew install node

Install Git

1
$ brew install git

Install Hexo

1
2
3
4
5
$ npm install -g hexo-cli
$ hexo init blog
$ cd blog && npm install
$ hexo generate
$ hexo server

Now open http://localhost:4000/ in your browser, you can see a built-in blog.

Common Commands

1
2
3
4
$ hexo n # create a new post or page
$ hexo g # generate static files, which are located in the public folder
$ hexo s # start the local web server, which is running at http://localhost:4000
$ hexo d # deploy the blog to remote end (such as Github)

Start a New Post

1
2
$ hexo new "post name" # create a new post
$ hexo new page "page name" # create a new page

Hexo Theme

Install

The theme that I used is Next.

1
2
$ cd blog
$ git clone https://github.com/iissnan/hexo-theme-next themes/next

Enable

After cloning, open the _config.yml file under the root directory, find the theme keyword, and change its value to next.

1
theme: next

Now refresh the page http://localhost:4000/, you can see the theme is enabled.

Git

Hexo Deploy

Edit the _config.yml file. Under the deploy, add your github repository and set the branch to master.

1
2
3
4
deploy:
type: git
repo: git@github.com:alickzhang/alickzhang.github.io.git
branch: master

Then execute the following command.

1
$ hexo d

Reference

hexo你的博客
手把手教你使用Hexo + Github Pages搭建个人独立博客