更新Jekyll

更新码云博客后,想在本地测试一下。上次更新仓库是2年前了,这次爆出一堆问题,参考网上一篇文章解决了。

报错

% jekyll serve
zsh: /usr/local/bin/jekyll: bad interpreter: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: no such file or directory

查看ruby版本

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

一、更新jekyll

sudo gem install bundler jekyll

又装了一大堆东西。

新的报错

% jekyll serve  
Traceback (most recent call last):
	12: from /usr/local/bin/jekyll:23:in `<main>'
	11: from /usr/local/bin/jekyll:23:in `load'
	10: from /Library/Ruby/Gems/2.6.0/gems/jekyll-4.0.0/exe/jekyll:11:in `<top (required)>'
	 9: from /Library/Ruby/Gems/2.6.0/gems/jekyll-4.0.0/lib/jekyll/plugin_manager.rb:52:in `require_from_bundler'
	 8: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler.rb:107:in `setup'
	 7: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/runtime.rb:20:in `setup'
	 6: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/runtime.rb:108:in `block in definition_method'
	 5: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/definition.rb:226:in `requested_specs'
	 4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/definition.rb:237:in `specs_for'
	 3: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/definition.rb:170:in `specs'
	 2: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/spec_set.rb:85:in `materialize'
	 1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/spec_set.rb:85:in `map!'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/spec_set.rb:91:in `block in materialize': Could not find public_suffix-3.0.2 in any of the sources (Bundler::GemNotFound)

更新bundle。很慢,还以为卡死了。中间要输密码。
太慢了,因为Gemfile.lock写死了gem的源:

GEM
  remote: https://rubygems.org/

改镜像

$ bundle config mirror.https://rubygems.org https://gems.ruby-china.com

改完镜像,瞬间升级完成

% bundle update

还是报错

% jekyll serve 
Traceback (most recent call last):
	10: from /usr/local/bin/jekyll:23:in `<main>'
	 9: from /usr/local/bin/jekyll:23:in `load'
	 8: from /Library/Ruby/Gems/2.6.0/gems/jekyll-4.0.0/exe/jekyll:11:in `<top (required)>'
	 7: from /Library/Ruby/Gems/2.6.0/gems/jekyll-4.0.0/lib/jekyll/plugin_manager.rb:52:in `require_from_bundler'
	 6: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler.rb:107:in `setup'
	 5: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/runtime.rb:26:in `setup'
	 4: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/runtime.rb:26:in `map'
	 3: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/forwardable.rb:230:in `each'
	 2: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/forwardable.rb:230:in `each'
	 1: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/runtime.rb:31:in `block in setup'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/runtime.rb:319:in `check_for_activated_spec!': You have already activated i18n 1.8.2, but your Gemfile requires i18n 0.9.5. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)

解:
加上bundle exec,运行成功

% bundle exec jekyll serve
Configuration file: /Users/luojinrong/code/GitHub/obarong.github.io/_config.yml
            Source: /Users/luojinrong/code/GitHub/obarong.github.io
       Destination: /Users/luojinrong/code/GitHub/obarong.github.io/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
       Jekyll Feed: Generating feed for posts
                    done in 0.708 seconds.
 Auto-regeneration: enabled for '/Users/luojinrong/code/GitHub/obarong.github.io'
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.

二、升级本地仓库用的Jekyll版本(这节可以跳过)

在仓库目录查看Jekyll版本会出现之前那个报错,要去没有Gemfile的目录。

% jekyll -v
jekyll 4.0.0

在仓库目录实际用的是3.8.6

% bundle exec jekyll -v
jekyll 3.8.6

修改Gemfile

gem "jekyll", "~> 4.0.0"

更新

% bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/..
You have requested:
  jekyll ~> 4.0.0

The bundle currently has jekyll locked at 3.8.6.
Try running `bundle update jekyll`

If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`
% bundle update jekyll

成功升级仓库的Jekyll。这下可以直接执行jekyll serve了。

三、本地改用GitHub pages主题

为什么GitHub pages的显示效果比我本地的好?

修改Gemfile

#gem "jekyll", "~> 4.0.0"
……
gem "github-pages", group: :jekyll_plugins

报错

% bundle update github-pages
Could not find gem 'github-pages'.

解:

% sudo gem install github-pages

install和update走起

% bundle update

这下本地浏览效果跟GitHub一模一样,但是要加bundle exec启动。

参考

解决因macOS High Sierra更新Ruby到2.3造成的Jekyll不能启动的问题 | 大专栏
https://www.dazhuanlan.com/2019/08/21/5d5c525c9e454/

bundle install 无响应问题 | 大专栏
https://www.dazhuanlan.com/2020/01/07/5e142e02df589/

个人博客搭建之一步步使用Github Page创建博客主页(2) | 大专栏
https://www.dazhuanlan.com/2020/02/02/5e366f389c663/

posted @ 2020-03-30 00:03  奥巴荣  阅读(1012)  评论(0编辑  收藏  举报