Skip to the essay
ShemolSetting up a Hexo + GitHub blog on Ubuntu (Zorin)
流程记录

Setting up a Hexo + GitHub blog on Ubuntu (Zorin)

Based on a Zhihu article. The reference is more detailed; where this differs, follow this post.

https://zhuanlan.zhihu.com/p/35668237

Install Node.js

plain text
sudo apt install nodejs

Hit a version problem right away. Ubuntu's Node is too old; Node.js should be upgraded to the latest.

https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

Use n module from npm in order to upgrade node

plain text
sudo npm cache clean -f
sudo npm install -g n
sudo n stable

To upgrade to latest version (and not current stable) version, you can use

plain text
sudo n latest
  • Fix PATH:
plain text
sudo apt-get install --reinstall nodejs-legacy     # fix /usr/bin/node
  • To undo:
plain text
sudo n rm 6.0.0     # replace number with version of Node that was installed
sudo npm uninstall -g n

You may need to restart your terminal to see the updated node version.

Some of the later steps can follow the original article; I won't repeat them.

Install Hexo

Follow the official method.

https://hexo.io/index.html

plain text
npm install hexo-cli -g
hexo init blog
cd blog
npm install
hexo server

If a step fails you can try adding sudo?

Connect GitHub and the local machine

plain text
npm install hexo-deployer-git --save
shell
git config --global user.name "SherlockShemol"
git config --global user.email "shemol@163.com"

Generate an SSH key

shell
ssh-keygen -t rsa -C "shemol@163.com"
shell
cat ~/.ssh/id_rsa.pub

Copy the output into the box, paste it under SSH keys, confirm and save.

Run ssh -T git@github.com. If your username appears, it worked.

Open _config.yml in the blog root. That's the blog config; you can change various blog-related settings there.

Change the last deploy block:

shell
deploy:
  type: git
  repository: <https://github.com/SherlockShemol/SherlockShemol.github.io>
  branch: master

Set repository to your own GitHub project URL.

Change the theme

See the original blog.

Mine is the Even theme, GitHub

npm install errors under Even

https://sobaigu.com/hexo-renderer-sass-error.html

Use

plain text
npm uninstall hexo-renderer-sass
npm i --save hexo-renderer-sass-next

The rest is in the docs.

Hexo deploy issues

GitHub's new rule: pushing from Hexo now requires a token.

Fix:

  1. Go to Settings->Developer settings->Personal access tokens->Personal access tokens and generate a new token
  2. After hexo -d a dialog asks for account and password. The password here is the token, not your GitHub password

Reference: https://blog.csdn.net/qq_21040559/article/details/122621179