菜单
菜单
文章目录
  1. 安装依赖
    1. 安装Git
    2. 安装Nodejs
    3. 安装NPM
    4. NPM换源
    5. 安装hexo
    6. 安装Yarn
    7. Yarn换源
  2. 部署Hexo
    1. 克隆源码
    2. 安装Hexo依赖和插件
    3. 预览调试
  3. 部署Hexo
    1. 配置SSH
    2. Push新文章
    3. 博客部署
  4. 结束语

Linux Mint 下搭建 Hexo 博客

本文记述在Linux Mint系统上安装Hexo并提交源码到Github仓库的办法。

另,提交并部署 Hexo 部分需阅读自动化多线部署Hexo博客

安装依赖

安装Git

在终端中运行命令:

sudo apt install git

安装Nodejs

在终端中运行命令:

sudo apt install nodejs

安装NPM

在终端中运行命令:

sudo apt install npm

NPM换源

执行以下命令即可换源

##临时使用
npm --registry https://registry.npm.taobao.org install express
##永久使用
npm config set registry https://registry.npm.taobao.org

安装hexo

在终端中运行命令:

npm install hexo --save
npm install hexo-cli -g

安装Yarn

此处可选,若继续使用npm包管理器可跳过。

sudo apt install yarn

Yarn换源

在终端中运行命令:

yarn config set registry https://registry.npm.taobao.org

部署Hexo

克隆源码

使用Git克隆Github仓库中备份的源码:

git clone git@github.com:Senorui/Blog.git

安装Hexo依赖和插件

在终端中运行命令:

##使用NPM
npm install
##使用Yarn
yarn install

预览调试

在终端中执行命令:

hexo cl && hexo g && hexo s

在浏览器中打开:http://localhost:4000/ 看是否成功运行。

部署Hexo

配置SSH

在Linux Mint 上生成新的SSH秘钥

$ git config --global user.name "你要设置的名字"
$ git config --global user.email "你要设置的邮箱"
$ ssh-keygen -t rsa -C "你刚刚设置的邮箱"
$ cd ~/.ssh # 进入虚拟目录ssh文件中
$ cat id_rsa.pub # 显示id_rsa.pub文件内容

验证是否配置成功

ssh -T git@github.com

当显示设置的名字即为成功。

Push新文章

写好一篇新文章后,重新将博客源代码Push到备份仓库即可。

在根目录建一个文件deploy.sh

git add
git commit -m "Update"
git branch -M master
git remote add origin git@github.com:Senorui/Blog.git
git push origin master
git push --force origin master

以后Push新文章只需以下执行命令即可

sh deploy.sh

博客部署

本站采用自动化部署,若想了解请参考文章: 自动化多线部署Hexo博客

结束语

至此,完成了Hexo博客在Linux Mint上的搭建与部署。

其中将源码备份在Github仓库内,需要时再Git下来,这也算是一种在不同平台上的迁移方法吧。

本文作者: Senorui

本文链接: https://senorui.top/posts/337b.html

版权声明: 本站所有文章除特别声明外,均采用【CC BY-NC-ND 4.0】国际许可协议,若转载请注明出处!

支持一下
知识无价,欢迎打赏🍖
  • 微信扫一扫
  • 支付宝扫一扫