You've successfully subscribed to The Daily Awesome
Great! Next, complete checkout for full access to The Daily Awesome
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Ubuntu 18.04 LTS 安装 Hexo

. 1 min read

安装 Hexo

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

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

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

    $ hexo init <blog>
    $ cd <blog>
    $ npm install


    ├── _config.yml
    ├── package.json
    ├── scaffolds
    ├── source
    |   ├── _drafts
    |   └── _posts
    └── themes
  3. 【可选】配置主题 Next

    $ cd <blog>
    $ git clone themes/next
  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

    $ ssh-keygen -t rsa -b 4096 -C "<[email protected]>"
  2. 将 内容复制并粘贴至 Github > Settings > SSH and GPG keys > New SSH key


  3. 测试

    $ ssh -T [email protected]


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

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

    $ cd <blog>

    配置 _config.yml

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

      type: git
      repo: <[email protected]:userName/repoName.git>
      branch: [branchName]
    • 编辑 admin 分支:

      deployCommand: './admin_script/'
    $ mkdir ./admin_script

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

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