Hexo安装

1.环境配置

1.安装Git

windows:到Git官网上下载

linux:对linux来说实在是太简单了,因为最早的git就是在linux上编写的,只需要一行代码。

1
sudo apt-get install git

安装好后,用git --version 来查看一下版本

2.安装nodejs

windows:nodejs选择LTS版本就行了

linux:安装脚本

安装完后,打开命令行,检查一下有没有安装成功。

1
2
node -v
npm -v

windows在git安装完后,就可以直接使用git bash来敲命令行了。

2.安装Hexo

1.安装

先创建一个文件夹blog,然后cd到这个文件夹

1
npm install -g hexo-cli

依旧用hexo -v查看一下版本

2.初始化

1
hexo init myblog

这个myblog可以自己取什么名字都行

1
2
cd myblog
npm install

完成后,指定文件夹目录下有:

  • node_modules: 依赖包

  • public:存放生成的页面

  • scaffolds:生成文章的一些模板

  • source:用来存放你的文章

  • themes:主题

  • ** _config.yml: 博客的配置文件**

3. 生成,部署

1
2
3
hexo clean
hexo g
hexo s

在浏览器输入127.0.0.1:4000就可以看到你生成的博客了。

3.添加SSH到GitHub

可跳过这边,到GitHub生成认证token

1.配置全局变量

1
2
git config --global user.name "yourname"
git config --global user.email "youremail"

2.检查

1
2
git config user.name
git config user.email

3.创建SSH

1
ssh-keygen -t rsa -C "youremail"

4.署到GitHub

1.修改配置

这一步,我们就可以将hexo和GitHub关联起来,也就是将hexo生成的文章部署到GitHub上,打开站点配置文件 _config.yml,翻到最后。

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

2.安装插件

1
npm install hexo-deployer-git --save

3.生成,部署

1
2
3
hexo clean	#清除缓存
hexo g #生成
hexo d #上传

注意deploy时可能要你输入用户名和密码。

5.更换设备操作

一样的,跟之前的环境搭建一样,

1.安装git

1
sudo apt-get install git

2.安装nodejs,npm

安装脚本

1
2
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

3.配置全局变量

1
2
git config --global user.name "yourgithubname"
git config --global user.email "yourgithubemail"

4.安装hexo

1
npm install hexo-cli -g

但是已经不需要初始化了

5.克隆代码

1
git clone git@https://github.com/YourgithubName/YourgithubName.github.io.git

然后进入克隆到的文件夹:

1
2
npm install
npm install hexo-deployer-git --save

6.生成,部署

1
2
hexo g
hexo d

然后就可以开始写你的新博客了

1
hexo new newpage

Tips:

不要忘了,每次写完最好都把源文件上传一下

1
2
3
git add .
git commit –m "xxxx"
git push

如果是在已经编辑过的电脑上,已经有clone文件夹了,那么,每次只要和远端同步一下就行了。

1
git pull

git pull 强制覆盖本地

1
git fetch --all
1
git reset --hard origin/master

Hexo安装
https://kuan.pages.dev/article/dc9e160a.html
作者
IKun
发布于
2023年2月5日
许可协议