nodejs安装卸载以及hexo踩坑

Mac系统下nodejs安装

brew安装node

1
2
3
4
5
6
7
8
9
10
11
12
13
# 搜索可安装node版本
brew search node
# 安装指定版本node
brew install node@12
# 链接node
brew link node@12 --force
# 配置环境变量
echo export PATH="/usr/local/opt/node@12/bin:$PATH" >> /Users/baibisen/.bash_profile
# 重启bash_profile生效
source /Users/baibisen/.bash_profile
# 查看node版本
node -v
npm -v

brew卸载node

1
2
3
4
5
# 直接卸载node
brew uninstall node@12 --force
# 清除残留文件
brew doctor
brew cleanup

Mac系统下hexo安装与踩坑

hexo安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 安装好node后安装hexo客户端
npm install -g hexo-cli
# 查看hexo版本
hexo -v
# 安装好hexo初始化(如果是新文件夹)
hexo init <folder>
cd <folder>
# 进入hexo目录安装node相关包(重要!)
npm install
# hexo基础命令
hexo new "test"
hexo clean
hexo generate
hexo server
hexo deploy

hexo卸载

1
2
3
4
5
6
# 卸载hexo
npm uninstall hexo-cli -g
# npm查看安装目录是否有hexo残留
npm list -g
# 查看本地是否有hexo残留
which hexo

hexo问题解决

安装好hexo执行deploy命令时报错,当时我的node版本是node@15

1
2
3
4
5
6
7
8
9
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError [ERR_INVALID_ARG_TYPE]: The "mode" argument must be integer. Received an instance of Object
at copyFile (fs.js:1972:10)
at tryCatcher (/Users/baibisen/Workspace/hexo/github_page_source/node_modules/bluebird/js/release/util.js:16:23)
at ret (eval at makeNodePromisifiedEval (/usr/local/lib/node_modules/hexo-cli/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:13:39)
at /Users/baibisen/Workspace/hexo/github_page_source/node_modules/hexo-fs/lib/fs.js:144:39
at tryCatcher (/Users/baibisen/Workspace/hexo/github_page_source/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/baibisen/Workspace/hexo/github_page_source/node_modules/bluebird/js/release/promise.js:517:31)
......

查资料了解到可能是hexo的版本不支持过高的node版本,于是我把node版本降低到了node@14,重新deploy发现还是这个问题,最后降到node@12之后重新deploy发现不报错正常了。所以适配hexo建议node版本设置为node@12,待hexo官方修复这种兼容性bug。