Mac 下安装 jekyll

Mac 下安装 jekyll

1
sudo gem install jekyll

输入密码,但还是会提示没有写权限

1
2
ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.

原因是 Apple在OS X El Capitan中全面启用了名为System Integrity Protection (SIP)的系统完整性保护技术。受此影响,大部分系统文件即使在root用户下也无法直接进行修改。

  1. 升级ruby(推荐)
  • 安装RVM
    1
    curl -L get.rvm.io | bash -s stable

出现异常

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
gpg: Signature made 一  7/ 2 03:41:26 2018 CST
gpg: using RSA key 62C9E5F4DA300D94AC36166BE206C29FBF04FF17
gpg: Can't check signature: No public key
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found. Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).

GPG signature verification failed for '/Users/liningrui/.rvm/archives/rvm-1.29.4.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.4/1.29.4.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:

gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

or if it fails:

command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -

the key can be compared with:

https://rvm.io/mpapis.asc
https://keybase.io/mpapis

NOTE: GPG version 2.1.17 have a bug which cause failures during fetching keys from remote server. Please downgrade or upgrade to newer version (if available) or use the second method described above.

你是因为我本地安装了gpg,但是却没有它的公钥,所以我们需要先接受公钥到本地。

1
gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

然后再执行上述命令,就应该Ok了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
gpg: Signature made 一  7/ 2 03:41:26 2018 CST
gpg: using RSA key 62C9E5F4DA300D94AC36166BE206C29FBF04FF17
gpg: Good signature from "Michal Papis (RVM signing) <mpapis@gmail.com>" [unknown]
gpg: aka "Michal Papis <michal.papis@toptal.com>" [unknown]
gpg: aka "[jpeg image of size 5015]" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 409B 6B17 96C2 7546 2A17 0311 3804 BB82 D39D C0E3
Subkey fingerprint: 62C9 E5F4 DA30 0D94 AC36 166B E206 C29F BF04 FF17
GPG verified '/Users/liningrui/.rvm/archives/rvm-1.29.4.tgz'
Installing RVM to /Users/liningrui/.rvm/
Adding rvm PATH line to /Users/liningrui/.profile /Users/liningrui/.mkshrc /Users/liningrui/.bashrc /Users/liningrui/.zshrc.
Adding rvm loading line to /Users/liningrui/.profile /Users/liningrui/.bash_profile /Users/liningrui/.zlogin.
Installation of RVM in /Users/liningrui/.rvm/ is almost complete:

* To start using RVM you need to run `source /Users/liningrui/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.

它提示说要使用RVM需要将rvm添加到环境变量中。

1
2
source /Users/liningrui/.rvm/scripts/rvm
rvm -v

列出所有可用的ruby版本

1
rvm list known

安装最新版本的ruby(以2.5.1为例)

1
rvm install 2.5.1

安装jekyll

1
gem install jekyll

安装完成后,cd到项目根目录,使用以下命令即可运行jekyll环境,通过 localhost:4000 即可访问。

1
jekyll serve

提示

1
Dependency Error: Yikes! It looks like you don't have jekyll-paginate 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: 'cannot load such file -- jekyll-paginate' If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/!

安装即可

1
gem install jekyll-paginate

接下来就可以开始github pages之路了~

参考: