title: Linux下hexo配置 date: 2015-03-13 11:25:11 tags: [Hexo]

本地环境

  • CentOS6
  • 下载nvm(Node.js的版本管理器)软件

wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh #下载安装nvm(安装目录在/root/.nvm/)

  • 安装nvm软件

nvm install 0.10 #选择Node.js的安装版本 nvm ls #查看node.js的版本

安装Hexo

  • 安装hexo
    1
    2
    3
    4
    5
    
    npm install -g hexo	#使用npm安装hexo(此处安装并未完成)
    #如果显示command not found,就重启终端,然后使用nvm ls检查当前版本,如果没有使用命令
    nvm use 0.10	#即使用方才装的版本(使用此命令后安装成功)
    #或使用一下命令直接设置全局默认的node.js版本
    nvm alias default 0.10.26
    
  • 安装失败的原因可能是无法连接到官方服务器,或者是GFW(Great Firewall,中国国家防火墙或长城防火墙)的问题。 需修改npm镜像源使用config命令
    1
    2
    3
    4
    
    $ npm config set registry http://registry.cnpmjs.org  
    $ npm info underscore (如果上面配置成功,使用这个命令会有以下提示)  
    $ npm http GET http://registry.cnpmjs.org/underscore  
    $ npm http 200 http://registry.cnpmjs.org/underscore  
    
  • 命令行指定
    1
    2
    3
    
    $ npm --registry http://registry.cnpmjs.org info underscore   
    编辑 ~/.npmrc 加入以下内容可以使配置永久生效,就不用每次npm安装时都要运行指定源命令了  
    $ registry = http://registry.cnpmjs.org  
    
  • 使用以下命令对hexo进行初始化 这里我位于~目录,而且我想把我的个人博客放在~/hexo目录,需要放在其他目录直接改一下自己需要的目录就可以了
    1
    2
    
    $ hexo install hexo --save
    $ hexo init hexo
    
  • 本地环境到此结束,有木有很easy

初步预览

1
2
hexo generate 或 hexo g	#生成静态文件
hexo server 或 hexo s	#打开本地预览(http:localhost:4000)

配置git并发布

配置git并发布基于hexo和github的个人博客 首先编辑个人安装目录的_config.yml文件,找到一下内容并修改为git

deploy: type: git repository: https://github.com/Arvon2014/arvon2014.github.com.git(直接将github上的https项复制并粘贴) branch: master 运行以下命令设置git全局变量,即设置用户名和邮箱(需要先和github建立免密码登陆) git config –global user.name “Arvon” git config –global user.email “yafeng2011@126.com

免密码ssh公钥设置

  1. 是否安装了ssh,未装执行

yum install ssh

  1. 检查公钥

cd ~/.ssh #存在就删了

  1. 生成公钥私钥对

ssh-keygen -t rsa -C “you_email@youremail.com” cd ~/.ssh #验证

  1. 添加ssh公钥到github

将公钥(pub)的内容复制到Deploykeys里面

  1. 测试是否生效

ssh -T git@github.com