安装Jekyll本地环境

May 6, 2019

以下环境以 Ubuntu 为例,如果环境为 Mac OS 则把 apt install 换成 brew install

Jekyll 依赖 Ruby 语言,需要先安装

1
$ sudo apt install ruby

类似 pipPythonRubyGemsRuby 的包管理器,其终端命令为 gem。安装 Ruby 之后用 gem 直接安装 Jekyll 可能会报以下错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ sudo gem install jekyll 
Fetching: public_suffix-3.1.1.gem (100%)
Successfully installed public_suffix-3.1.1
Fetching: addressable-2.6.0.gem (100%)
Successfully installed addressable-2.6.0
Fetching: colorator-1.1.0.gem (100%)
Successfully installed colorator-1.1.0
Fetching: http_parser.rb-0.6.0.gem (100%)
Building native extensions. This could take a while...
ERROR:  Error installing jekyll:
	ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.5.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
/usr/bin/ruby2.5 -r ./siteconf20190706-17669-1vutbo1.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.5.0/gems/http_parser.rb-0.6.0 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/http_parser.rb-0.6.0/gem_make.out

因此需安装 Ruby 的开发插件

1
$ sudo apt-get install ruby`ruby -e 'puts RUBY_VERSION[/\d+\.\d+/]'`-dev

配置 Gem 国内加速源

1
$ sudo gem sources -r https://rubygems.org/ -a https://gems.ruby-china.com/

安装 Jekyll

1
$ sudo gem install jekyll

其次 Jekyll 还依赖 jekyll-paginate

1
$ sudo gem install jekyll-paginate

所有配置完成后,终端移动到目标文件夹下启动服务即可

1
$ jekyll serve

参考链接: