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
    

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

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

    $ cd <blog>
    $ git clone https://github.com/iissnan/hexo-theme-next 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. 将 id_rsa.pub 内容复制并粘贴至 Github > Settings > SSH and GPG keys > New SSH key

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

  3. 测试

    $ ssh -T [email protected]
    
    

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

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

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

    $ cd <blog>
    
    

    配置 _config.yml

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

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

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

    hexo-generate.sh 添加以下内容

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

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