The tutorial demonstration environment is macOS, and the steps for Windows are basically the same, so I won't elaborate further here.
Installation Preparation#
Before installing Hexo, you must ensure that the following two software are already installed on your computer:
- node.js
- git (it will prompt for installation, just agree)
Start Installation#
- Open the terminal tool and enter the following command to gain administrator privileges:
sudo su
- Install npm. Due to special circumstances in China, installing npm can be quite slow, so we will use Taobao's cnpm for installation:
npm install -g cnpm --registry=https://registry.npm.taobao.org
- Install Hexo:
cnpm install -g hexo-cli
-
Check if you are in the user directory; if so, continue. Otherwise, you need to enter the user directory first (usually the folder with your username).
-
Create a new directory; I will name it blog:
mkdir blog
- Enter the blog directory:
cd blog
- Initialize the blog:
sudo hexo init
Tip: INFO Start blogging with Hexo! indicates success.
- Local testing:
hexo s
Displays
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
- Open the above address in a browser to view the Hexo blog.
Publish a New Article#
- Create a new article:
hexo n "Article Title"
INFO Created: /Users/ching/blog/source/_posts/Article Title.md
-
Enter the article (here I will directly use the vim command to edit, of course, you can also use other Markdown editors).
-
Press i and then Enter to edit; I will just input some content randomly. After editing, press Esc and type to save.
-
Return to the blog directory and clean up:
hexo clear
- Generate website content:
hexo g
- Use the hexo s command again to start local testing and check if the publication was successful.
Publish Local Website to the Internet#
Today we will demonstrate how to publish the website to GitHub.
- Log in to GitHub.
- Create a new repository:
- Click the + icon in the upper right corner and select new repository.
- Repository name: GitHub username + github.io.
- Fill in the description.
- Click create repository to create it.
- Return to the local terminal and install the plugin hexo-deployer-git:
cnpm install --save hexo-deployer-git
- Open the configuration file:
vim _config.yml
- Move to the end of the document and edit:
deploy:
type: git
repo: https://github.com/username/custom_address.github.io.git
branch: master
- Deploy to GitHub:
hexo d
Enter GitHub account password, and display INFO Deploy done: git indicates success.
- Log in to our website to view it.