安装jekyll

过程的一些记录

Posted by 夜雨声烦 on October 13, 2022

按照Jekyll主页的Quickstart,在命令行输入指令:

1
gem install jekyll bundler

显示问题信息:

You don’t have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

根据Stack Overflow上的高亮回答解决:

You are correct that macOS won’t let you change anything with the Ruby version that comes installed with your Mac. However, it’s possible to install gems like bundler using a separate version of Ruby that doesn’t interfere with the one provided by Apple.

下为Monfresh推荐的解决办法:

1
2
3
4
5
6
7
8
# 用Homebrew下载chruby和ruby-install
brew install chruby ruby-install

# 安装最新版本的Ruby,下载完按照提示向.zshrc中加入一些export
ruby-install ruby

# 切换到下载的最新版本,我的是3.1.2,如果是其他版本会报错
chruby 3.1.2

然后顺利安装了jekyllbundler gems,运行下述指令:

1
2
3
4
5
6
7
# Build the site and make it available on a local server.[from Quickstart]
# Github Pages官网推荐使用Bundler运行Jekyll
bundle exec jekyll serve

# 同时推荐使用该指令
# Pass the --livereload option to serve to automatically refresh the page with each change you make to the source files
bundle exec jekyll serve --livereload

但是出现了一些报错,是由于缺失一些依赖包,运行 bundle install下载,这次成功运行了!

打开https://127.0.0.1:4000,成功展现网页:

10月25日更新

虽然之前已经将下列语句加入到 ~/.zshrc中:

1
2
3
source /usr/local/opt/chruby/share/chruby/chruby.sh
# To enable auto-switching of Rubies specified by .ruby-version files
source /usr/local/opt/chruby/share/chruby/auto.sh

但是每次打开终端发现并没有自动切换到 ruby-3.1.2,去Github上查看发现是没有创建.ruby-version文件:

在终端输入指令:

1
echo "ruby-3.1.2" > ~/.ruby-version

重新打开终端发现已自动切换。