要求

在 CentOS 7 中安装 Jekyll 3.0.0。

开始

1
2
yum install -y ruby rubygems
gem install jekyll

这时会提示错误:

1
2
3
4
5
6
7
8
9
Building native extensions.  This could take a while...
ERROR:  Error installing jekyll:
    ERROR: Failed to build gem native extension.

    /usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/share/include/ruby.h

Gem files will remain installed in /usr/local/share/gems/gems/ffi-1.9.10 for inspection.
Results logged to /usr/local/share/gems/gems/ffi-1.9.10/ext/ffi_c/gem_make.out

这是缺少 ruby 开发库 ruby-devel,用以下命令安装:

1
yum install -y ruby-devel

再次安装 Jekyll 时会提示:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Building native extensions.  This could take a while...
ERROR:  Error installing jekyll:
	ERROR: Failed to build gem native extension.

    /usr/bin/ruby extconf.rb
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib64
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/usr/bin/ruby
	--with-ffi_c-dir
	--without-ffi_c-dir
	--with-ffi_c-include
	--without-ffi_c-include=${ffi_c-dir}/include
	--with-ffi_c-lib
	--without-ffi_c-lib=${ffi_c-dir}/
	--with-libffi-config
	--without-libffi-config
	--with-pkg-config
	--without-pkg-config
/usr/share/ruby/mkmf.rb:434:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
	from /usr/share/ruby/mkmf.rb:565:in `try_cpp'
	from /usr/share/ruby/mkmf.rb:1044:in `block in have_header'
	from /usr/share/ruby/mkmf.rb:895:in `block in checking_for'
	from /usr/share/ruby/mkmf.rb:340:in `block (2 levels) in postpone'
	from /usr/share/ruby/mkmf.rb:310:in `open'
	from /usr/share/ruby/mkmf.rb:340:in `block in postpone'
	from /usr/share/ruby/mkmf.rb:310:in `open'
	from /usr/share/ruby/mkmf.rb:336:in `postpone'
	from /usr/share/ruby/mkmf.rb:894:in `checking_for'
	from /usr/share/ruby/mkmf.rb:1043:in `have_header'
	from extconf.rb:16:in `<main>'


Gem files will remain installed in /usr/local/share/gems/gems/ffi-1.9.10 for inspection.
Results logged to /usr/local/share/gems/gems/ffi-1.9.10/ext/ffi_c/gem_make.out

这是缺少 gcc 的问题,安装 gcc:

1
yum install -y gcc

总结

最终需要执行的命令是:

1
2
yum install -y ruby rubygems ruby-devel gcc
gem install jekyll