问题 new

2021年升级Mac M1了,Jekyll 又无法启动了。

$ jekyll server

解决

升级了一下Jekyll到4.2.1,新的安装命令:

$ gem install bundler jekyll
$ jekyll new my-awesome-site
$ cd my-awesome-site
$ bundle exec jekyll serve

先升级brew

$ brew update

安装脚本提示

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc

For compilers to find ruby you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"

For pkg-config to find ruby you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/ruby/lib/pkgconfig"

重新安装最新版本ruby

$ brew install ruby

查询ruby版本还是老的

$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]

MAC M1 环境下配置ruby运行路径

$ export PATH="/opt/homebrew/opt/ruby/bin:$PATH"

查询后是最新版本

$ ruby -v
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin20]

在新的ruby环境下重新安装

$ sudo gem install bundler jekyll

重新配置gem的Path

$ export PATH="/opt/homebrew/lib/ruby/gems/3.0.0/bin:$PATH"

再次查询就正确了

$ which jekyll                                           
/opt/homebrew/lib/ruby/gems/3.0.0/bin/jekyll

再次运行还是有问题,提示webrick错误 google一下,原来是jekyll默认少引用了一个包

$ bundle add webrick                              

把PATH参数加到 M1 默认终端配置文件 ~/.zshrc

$ sudo echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
$ sudo echo 'export PATH="/opt/homebrew/lib/ruby/gems/3.0.0/bin:$PATH"' >> ~/.zshrc

验证一下 ~/.zshrc

$ vim ~/.zshrc

接下来就正常了。

$ jekyll serve
//or
$ jekyll server
  1. Jekyll官网
  2. load error:cannot load such file webrick