在CentOS,Ubuntu
按照同样步骤安装,Ruby Gems
往往都无法搭建成,每次都是依赖不对,各种奇葩原因,解决办法就是使用 RVM
安装,解决 Ruby
的环境依赖管理,而且每次安装Jekyll
基本不会出错
本文主要介绍如何用一条靠谱的路子快速安装 Ruby
环境 搭建Jekyll
博客。
jekyll
是一个简单的免费的Blog
生成工具,类似WordPress
。但是和WordPress
又有很大的不同,原因是Jekyll
只是一个生成静态网页的工具,不需要数据库支持。但是可以配合第三方服务,例如Disqus
。最关键的是jekyll可以免费部署在Github上,而且可以绑定自己的域名。
CentOS 7.3 / Ubuntu 16.04
rvm 1.29.3
gem 2.5.1
ruby 2.3.0
jekyll 3.6.2
首先确定操作系统环境,不建议在 Windows 上面搞,如果你一定想在Windows
上安装Jekyll
参考:http://www.ymq.io/2017/07/22/Windows-install-Jekyll/
强烈新手使用 Ubuntu 省掉不必要的麻烦!
RVM 是干什么的这里就不解释了,自行Google,这里所有的命令都是再用户权限下操作的,任何命令最好都不要用 sudo
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
# 如果上面的连接失败,可以尝试:
curl -L https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable
期间可能会问你 sudo
管理员密码,以及自动通过 Homebrew
安装依赖包,等待一段时间后就可以成功安装好 RVM
。
然后,载入 RVM
环境(新开 Termal
就不用这么做了,会自动重新载入的)
source /usr/local/rvm/scripts/rvm
修改 RVM 的 Ruby 安装源到 Ruby China 的 Ruby 镜像服务器,这样能提高安装速度
echo "ruby_url=https://cache.ruby-china.org/pub/ruby" >> /usr/local/rvm/user/db
检查一下是否安装正确
$ rvm -v
rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
用 RVM 安装 Ruby 环境
$ rvm requirements
$ rvm install 2.3.0
等待漫长的下载,编译过程,完成以后,Ruby, Ruby Gems
就安装好了,国内速度很慢,国外服务器,不到一分钟就下载完了,文件大概100兆
设置 Ruby 版本,同样,也可以用其他版本号,前提是你有用 rvm install 安装过那个版本
rvm use 2.3.0 --default
这个时候你可以测试是否正确
$ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
$gem -v
2.5.1
gem install bundler
搭建Jekyll博客,需要找一套主题模板,这里可以参考:https://www.zhihu.com/question/20223939 ,以下以 mzlogin.github.io 的主题为例
CentOS
yum install git
Ubuntu
apt install git
git clone https://github.com/mzlogin/mzlogin.github.io.git
cd mzlogin.github.io.git/
bundle install
jekyll serve -H 0.0.0.0 -P 80
效果如下
Ubuntu 16.04
## Configuration file: /root/mzlogin.github.io/_config.yml
Dependency Error: Yikes! It looks like you don't have jekyll-remote-theme or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: 'Could not open library 'libcurl': libcurl: cannot open shared object file: No such file or directory. Could not open library 'libcurl.so': libcurl.so: cannot open shared object file: No such file or directory. Could not open library 'libcurl.so.4': libcurl.so.4: cannot open shared object file: No such file or directory' If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/!
jekyll 3.6.2 | Error: jekyll-remote-theme
执行
apt-get install libcurl3
博客搭建成功之后,还需要做一些事情才能让你的页面「正确」跑起来。
以下内容摘自 码志 博客主题的,Fork 指南
username.github.io
的项目的 master 分支,或者其它名称的项目的 gh-pages 分支可以自动生成 GitHub Pages 页面。
我的个人博客外观基于 DONGChuan 的修改,感谢 Zhuang Ma !