0%

ubuntu环境下安装及部署hexo

在ubuntu环境下安装hexo及及其依赖,并部署到github上,将个人域名解析到博客仓库

安装Node.js、Git、hexo

  1. 安装Node.js
    在终端输入以下命令

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    sudo apt-get update
    sudo apt-get install -y python-software-properties software-properties-common
    sudo add-apt-repository ppa:chris-lea/node.js
    sudo apt-get update
    sudo apt-get install nodejs
    sudo apt install nodejs-legacy
    sudo apt install npm
    sudo npm install n -g
    sudo n stable
    sudo node -v
  2. 安装Git

    1
    sudo apt-get install git
  3. 安装hexo

    1
    sudo npm install -g hexo-cli

    在本地创建网站

  4. 创建一个网站

    1
    2
    3
    sudo hexo init hexo
    cd hexo
    sudo npm install
  5. 新建一个博客
    source中默认已有一个hello_world博客,新建博客命令如下

    1
    hexo n myblog

    执行该命令后,会在hexo/source/_posts文件夹下生成一个myblog.md文件

  6. 本地预览博客
    输入下面命令,将博客部署到本地

    1
    2
    hexo g 
    hexo s

    执行之后打开浏览器输入localhost:4000即可预览网页

部署到github

  1. 创建github仓库
    登陆github账号,新建一个仓库,仓库名字必须是username.github.io,权限设置为public
  2. 配置git
    详情清查阅git使用手册
  3. 修改_config.yml
    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    repo: git@github.com:你的GitHub用户名/你的GitHub用户名.github.io.git
    branch: master
  4. 上传到github
    1
    hexo d
    执行命令即可部署到github,然后可以通过username.github.io访问博客主页了,以后新建博客部署只需执行以下命令
    1
    2
    3
    4
    hexo n name //新建一个博客,然后修改ia.md文件内容
    hexo clean //清除缓存
    hexo g // 生成部署文件
    hexo d //上传

绑定个人域名

如果觉得每次通过username.gituhb.io访问博客很low,可以去域名服务商注册一个域名,然后添加解析到博客地址,即可通过个人域名访问博客

  1. 在source文件夹下新建一个CNAME文件,不带后缀,打开后将个人域名写入文件,不要加http和www,例如我的域名是 windflying.com

pic

  1. 添加解析的内容如下