搭建 Jekyll & GitHub 环境

| 分类 technology  | 标签 Jekyll  GitHub  Ubuntu  Ruby 

安装Ruby

  1. 安装curl:

    # 检查是否已经安装
    $ dpkg -s curl
    # 安装命令
    $ sudo apt-get install curl
    
  2. 安装RVM:

    $ curl -L get.rvm.io | bash -s stable
    

    在$HOME/.bash_profile和$HOME/.bashrc中添加

    [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
    # This loads RVM into a shell session.
    

    重启终端后查看RVM版本

    $ rvm -v
    

    通过rvm requirements命令,查看需要安装那些依赖包,之后将它们安装

    $ sudo apt-get install a b c d
    # 两个包之间用空格隔开
    
  3. 安装ruby

    察看当前RVM中已经安装的ruby版本

    $ rvm list	#应该是没有任一版本
    

    察看RVM可供安装的ruby版本

    $ rvm list known
    

    安装ruby 2.1-head

    $ rvm install 2.1-head
    

    检查版本

    $ rvm list
    

    选择2.1作为当前的使用版本,并且设置为缺省

    $ rvm use ruby-2.1-head --default
    

    设置好之后察看ruby版本

    $ ruby -v
    

    察看ruby的路径,就是RVM帮我们安装的

    $ which ruby
    

安装node.js

安装原因可参见 Ruby China

  1. 从nodeJS官网http://nodejs.org/下载最新源代码包:node-vx.x.xx.tar.gz
  2. 解压并复制到/usr/lib中

    $ cp -r [源文件夹] [目的文件夹]
    
  3. 切换到文件目录

    $ ./configure 
    $ make
    $ make install
    $ node --version
    

安装jekyll

  1. 执行代码

    $ gem install jekyll
    $ jekyll -v
    $ gem install rdiscount
    $ gem install kramdown 
    
  2. 建立博客

    $ cd ~
    $ jekyll new blog_name	#blog_name为博客目录名字,可自取
    $ cd blog_name
    $ jekyll server
    
  3. 访问http://localhost:4000即可在本地访问。


安装git

可查看官方文档http://www.git-scm.com/book/zh/

  1. 执行代码进行安装

    $ apt-get install git
    

    若提示已安装最新版,则继续下边操作

  2. 初次运行Git前的配置

    $ git config --global user.name "John Doe"
    $ git config --global user.email johndoe@example.com
    

    查看配置信息

    $ git config --list
    

配置github

  1. Check for SSH keys

    $ ls -al ~/.ssh
    # Lists the files in your .ssh directory, if they exist
    
  2. Generate a new SSH key

    若没有SSH keys,则进行以下操作

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    # Creates a new ssh key, using the provided email as a label
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/you/.ssh/id_rsa):
    

    直接按Enter即可

    Enter passphrase (empty for no passphrase): [Type a passphrase]
    # Enter same passphrase again: [Type passphrase again]
    

    之后得到

    Your identification has been saved in /home/you/.ssh/id_rsa.
    # Your public key has been saved in /home/you/.ssh/id_rsa.pub.
    # The key fingerprint is:
    # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com
    

    Then add your new key to the ssh-agent:

    # start the ssh-agent in the background
    eval "$(ssh-agent -s)"
    # Agent pid 59566
    ssh-add ~/.ssh/id_rsa
    
  3. Add your SSH key to GitHub

    Run the following code to copy the key to your clipboard.

    sudo apt-get install xclip
    # Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)
    
    xclip -sel clip < ~/.ssh/id_rsa.pub
    # Copies the contents of the id_rsa.pub file to your clipboard
    

    Now that you have the key copied, it’s time to add it into GitHub:

    In the user bar in the top-right corner of any page, click Account settings.

    Click SSH Keys in the left sidebar.

    Click Add SSH key.

    In the Title field, add a descriptive label for the new key. For example, if you’re using a personal Mac, you might call this key “Personal MacBook Air”.

    Paste your key into the “Key” field.

    Click Add key.

    Confirm the action by entering your GitHub password.

  4. Test everything out

    $ ssh -T git@github.com
    # Attempts to ssh to github
    

    You may see this warning:

    The authenticity of host 'github.com (207.97.227.239)' can't be established.
    # RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
    # Are you sure you want to continue connecting (yes/no)?
    

    Don’t worry! This is supposed to happen. Verify that the fingerprint in your terminal matches the one we’ve provided up above, and then type “yes.”

    Hi username! You've successfully authenticated, but GitHub does not
    # provide shell access.
    

    If that username is yours, you’ve successfully set up your SSH key! Don’t worry about the “shell access” thing, you don’t want that anyway.


jekyll与github pages配合

  1. Create a repository

    Head over to GitHub and create a new repository named username.github.io, where username is your username (or organization name) on GitHub.

  2. Clone the repository

    Go to the folder where you want to store your project, and clone the new repository:

    $ git clone https://github.com/username/username.github.io
    
  3. Hello World

    Enter the project folder and add an index.html file:

    $ cd username.github.io
    $ echo "Hello World" > index.html
    
  4. Push it

    Add, commit, and push your changes:

    $ git add --all
    $ git commit -m "Initial commit"
    $ git push
    
  5. …and you’re done!

    Fire up a browser and go to http://username.github.io. Give it a couple of minutes for your page to show up—there will be a delay this very first time. In the future, changes will show up pretty much instantly.


上一篇     下一篇