Ubuntu 18.04 LTS 安装 Hexo

安装 Hexo

使用sudo npm install hexo -gsudo npm install hexo-cli -g 安装 Hexo 报错,安装失败

  1. 使用如下命令可以正常安装 Hexo

    1
    
    $sudo npm install --unsafe-perm --verbose -g hexo
    
  2. 配置工作目录

    1
    2
    3
    
    $ hexo init <blog>
    $ cd <blog>
    $ npm install
    

    新建完成后,指定文件夹的目录如下:

    1
    2
    3
    4
    5
    6
    7
    8
    
    <blog>
    ├── _config.yml
    ├── package.json
    ├── scaffolds
    ├── source
    |   ├── _drafts
    |   └── _posts
    └── themes
    
  3. 【可选】配置主题 Next

    1
    2
    
    $ cd <blog>
    $ git clone https://github.com/iissnan/hexo-theme-next themes/next
    
  4. 配置插件

    1
    2
    3
    4
    
    $npm install hexo-server -g
    $npm install hexo-admin -g
    $npm install hexo-deployer-git -g
    $npm install hexo-util -g
    
  5. 启动服务

    hexo server

  6. 其他细节

    • 主页 http://localhost:4000
    • 管理员主页 http://localhost:4000/admin
      • 添加密码: http://localhost:4000/admin/#/auth-setup

自动备份至 Github

  1. 生成 SSH key

    如报错可检查 hexo-deployer-git

    1
    
    $ ssh-keygen -t rsa -b 4096 -C "<your_email@example.com>"
    
  2. 将 id_rsa.pub 内容复制并粘贴至 Github > Settings > SSH and GPG keys > New SSH key

    特别注意不要有多余的回车,(应该是没有换行符)

  3. 测试

    1
    
    $ ssh -T git@github.com
    

    会提示是否确认链接,输入yes就好,若链接成功则会返回

    Hi xxx! You’ve successfully authenticated, but GitHub does not provide shell access.

  4. 使用管理员后台一键发布

    1
    
    $ cd <blog>
    

    配置 _config.yml

    1
    
    $ vim _config.yml
    
    • 编辑 deploy 分支:

      1
      2
      3
      4
      
      deploy:
      type: git
      repo: <git@github.com:userName/repoName.git>
      branch: [branchName]
      
    • 编辑 admin 分支:

      1
      
      deployCommand: './admin_script/hexo-generate.sh'
      
    1
    
    $ mkdir ./admin_script
    

    hexo-generate.sh 添加以下内容

    #!/usr/bin/env sh
    hexo g -d
    

    添加权限后使用后台的 deploy 即可一键同步至 Github

updatedupdated2023-01-302023-01-30
点击刷新