欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mac系统搭建hexo环境

程序员文章站 2022-07-07 21:34:32
...


Hexo官网有详细的安装步骤

安装Git

Git官网下载

测试git是否安装成功

MacdeMacBook-Air:~ crocutax$ git --version
git version 2.14.1

安装Node.js

1.先安装nvm Node Version Manager

打开终端,输入:

cURL:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

Wget:

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

通过如下指令测试nvm是否安装成功

MacdeMacBook-Air:~ crocutax$ command -v nvm
nvm

如果出现Comman not found提示

-bash: nvm: command not found

则尝试

  • 重新打开终端
  • 输入指令:source ~/.bashrc

2.nvm安装完毕后,通过nvm安装node.js

$ nvm install stable

如下指令代表安装成功

MacdeMacBook-Air:~ crocutax$ nvm install stable
Downloading and installing node v8.6.0...
Downloading https://nodejs.org/dist/v8.6.0/node-v8.6.0-darwin-x64.tar.gz...
######################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v8.6.0 (npm v5.3.0)
Creating default alias: default -> stable (-> v8.6.0)

安装hexo

MacdeMacBook-Air:~ crocutax$ sudo npm install -g hexo
/Users/mac/.nvm/versions/node/v8.6.0/bin/hexo -> /Users/mac/.nvm/versions/node/v8.6.0/lib/node_modules/hexo-cli/bin/hexo

> [email protected] install /Users/mac/.nvm/versions/node/v8.6.0/lib/node_modules/hexo-cli/node_modules/dtrace-provider
> node scripts/install.js


> [email protected] install /Users/mac/.nvm/versions/node/v8.6.0/lib/node_modules/hexo-cli/node_modules/fsevents
> node install

[fsevents] Success: "/Users/mac/.nvm/versions/node/v8.6.0/lib/node_modules/hexo-cli/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile

> [email protected] postinstall /Users/mac/.nvm/versions/node/v8.6.0/lib/node_modules/hexo-cli/node_modules/hexo-util
> npm run build:highlight


> [email protected] build:highlight /Users/mac/.nvm/versions/node/v8.6.0/lib/node_modules/hexo-cli/node_modules/hexo-util
> node scripts/build_highlight_alias.js > highlight_alias.json

+ [email protected]
added 217 packages in 72.766s
MacdeMacBook-Air:~ crocutax$ 

使用hexo -version指令测试hexo是否安装成功

MacdeMacBook-Air:~ crocutax$ hexo -version
hexo-cli: 1.0.3
os: Darwin 16.6.0 darwin x64
http_parser: 2.7.0
node: 6.10.2
v8: 5.1.281.98
uv: 1.9.1
zlib: 1.2.11
ares: 1.10.1-DEV
icu: 58.2
modules: 48
openssl: 1.0.2k

初始化Hexo目录

创建自己的博客文件夹,然后cd到该目录下

1.执行指令hexo init初始化hexo

MacdeMacBook-Air:~ crocutax$ cd /Users/mac/Desktop/crocutax/blog
MacdeMacBook-Air:blog crocutax$ hexo init
INFO  Cloning hexo-starter to ~/Desktop/crocutax/blog
Cloning into '/Users/mac/Desktop/crocutax/blog'...
remote: Counting objects: 59, done.
remote: Total 59 (delta 0), reused 0 (delta 0), pack-reused 59
Unpacking objects: 100% (59/59), done.
Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into '/Users/mac/Desktop/crocutax/blog/themes/landscape'...
remote: Counting objects: 785, done.        
remote: Total 785 (delta 0), reused 0 (delta 0), pack-reused 784        
Receiving objects: 100% (785/785), 2.54 MiB | 142.00 KiB/s, done.
Resolving deltas: 100% (403/403), done.
Submodule path 'themes/landscape': checked out 'decdc2d9956776cbe95420ae94bac87e22468d38'
INFO  Install dependencies
npm WARN deprecated [email protected]: This package is no longer maintained

> [email protected] install /Users/mac/Desktop/crocutax/blog/node_modules/dtrace-provider
> node scripts/install.js


> [email protected] install /Users/mac/Desktop/crocutax/blog/node_modules/fsevents
> node install

[fsevents] Success: "/Users/mac/Desktop/crocutax/blog/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile

> [email protected] postinstall /Users/mac/Desktop/crocutax/blog/node_modules/hexo-util
> npm run build:highlight


> [email protected] build:highlight /Users/mac/Desktop/crocutax/blog/node_modules/hexo-util
> node scripts/build_highlight_alias.js > highlight_alias.json

npm notice created a lockfile as package-lock.json. You should commit this file.
added 429 packages in 30.513s
INFO  Start blogging with Hexo!
MacdeMacBook-Air:blog crocutax$ 

2.安装npm

输入指令:npm install

3.启动hexo本地服务

MacdeMacBook-Air:blog crocutax$ hexo s
INFO  Start processing
INFO  Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.

此时,打开http://localhost:4000/就可以看到hexo的默认首页了,hexo搭建完毕!

注意事项

hexo初始化的目录必须是空目录,所以如果是文件迁移,那么先hexo初始化空目录,然后再文件覆盖即可.

其他配置请参考:

Hexo+Github Pages搭建个人博客