MAC下Jekyll环境搭建
作者:互联网
1.Jekyll简介
Jekyll 是一个简单的博客形态的静态站点生产机器。它有一个模版目录,其中包含原始文本格式的文档,通过 Markdown (或者 Textile) 以及 Liquid 转化成一个完整的可发布的静态网站,你可以发布在任何你喜爱的服务器上。Jekyll 也可以运行在 GitHub Page 上,也就是说,你可以使用 GitHub 的服务来搭建你的项目页面、博客或者网站,而且是完全免费的。
2.安装Jekyll
安装 Jekyll首先需要Ruby环境的支持,部分Mac自带,没有则需要安装
2.1.安装Rvm
Rvm是一个命令行工具,可以提供一个便捷的多版本 Ruby 环境的管理和切换
在控制台输入以下命令,然后回车:
$ curl -sSL https://get.rvm.io | bash -s stable
控制台输出如下:
Downloading https://github.com/rvm/rvm/archive/1.29.7.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.7/1.29.7.tar.gz.asc
Found PGP signature at: 'https://github.com/rvm/rvm/releases/download/1.29.7/1.29.7.tar.gz.asc',
but no GPG software exists to validate it, skipping.
省略.....
in all your open shell windows, in rare cases you need to reopen all shell windows.
切换Ruby镜像地址:
$ gem sources --remove https://rubygems.org/
$ gem sources --add https://gems.ruby-china.com/
$ gem sources -l
2.2.安装Ruby
列出可安装的版本信息(此处安装的是2.6.0):
$ rvm list known
安装一个ruby版本:
$ rvm install 2.6.0
如果想设置为默认版本,可以用这条命令来完成:
$ rvm use 2.4.0 —default
也可执行安装命令的时候直接设置为默认版本:
$ rvm install 2.6 —default
若提示以下信息,则是缺失软件包的管理器,需要安装Command-Line Tools
:
No binary rubies available for: osx/10.13/x86_64/ruby-2.6.0.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
touch: /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress: Permission denied
rm: /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress: Permission denied
执行以下命令来安装Command-Line Tools:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
静静等待,控制台输出以下信息则是安装成功:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The Xcode Command Line Tools will be installed.
Press RETURN to continue or any other key to abort
==> Searching online for the Command Line Tools
==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> Installing Command Line Tools (macOS High Sierra version 10.13) for Xcode-10.1
==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ (macOS\ High\ Sierra\ version\ 10.13)\ for\ Xcode-10.1
Software Update Tool
Downloading Command Line Tools (macOS High Sierra version 10.13) for Xcode
Downloaded Command Line Tools (macOS High Sierra version 10.13) for Xcode
Installing Command Line Tools (macOS High Sierra version 10.13) for Xcode
Done with Command Line Tools (macOS High Sierra version 10.13) for Xcode
Done.
==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
==> Downloading and installing Homebrew...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 119598 (delta 7), reused 18 (delta 2), pack-reused 119574
Receiving objects: 100% (119598/119598), 28.28 MiB | 99.00 KiB/s, done.
Resolving deltas: 100% (87381/87381), done.
From https://github.com/Homebrew/brew
省略.....
==> Installation successful!
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Next steps:
- Run `brew help` to get started
- Further documentation:
https://docs.brew.sh
再次执行Ruby安装命令:
$ rvm install 2.6 —default
控制台输出以下信息则是安装成功:
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.13/x86_64/ruby-2.6.0.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Installing requirements for osx.
Updating system......
Installing required packages: autoconf, automake, libtool, pkg-config, coreutils, libyaml, readline, libksba, openssl@1.1..............
Certificates bundle '/usr/local/etc/openssl@1.1/cert.pem' is already up to date.
Requirements installation successful.
省略.....
ruby-2.6.0 - #generating default wrappers.......
ruby-2.6.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.6.0 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
查看Ruby 版本:
$ ruby -v
ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin17]
2.3.安装Jekyll
通过上面的步骤,基础环境搭建好了,开始安装Jekyll,输入以下命令:
$ gem install jekyll
控制台输出如下:
Fetching addressable-2.6.0.gem
Fetching colorator-1.1.0.gem
Fetching http_parser.rb-0.6.0.gem
Fetching em-websocket-0.5.1.gem
Fetching public_suffix-3.0.3.gem
Fetching eventmachine-1.2.7.gem
Fetching concurrent-ruby-1.1.4.gem
Fetching i18n-0.9.5.gem
Fetching rb-fsevent-0.10.3.gem
Fetching ffi-1.10.0.gem
Fetching rb-inotify-0.10.0.gem
Fetching sass-listen-4.0.0.gem
Fetching sass-3.7.3.gem
Fetching jekyll-sass-converter-1.5.2.gem
省略.....
Parsing documentation for jekyll-3.8.5
Installing ri documentation for jekyll-3.8.5
Done installing documentation for public_suffix, addressable, colorator, http_parser.rb, eventmachine, em-websocket, concurrent-ruby, i18n, rb-fsevent, ffi, rb-inotify, sass-listen, sass, jekyll-sass-converter, ruby_dep, listen, jekyll-watch, kramdown, liquid, mercenary, forwardable-extended, pathutil, rouge, safe_yaml, jekyll after 43 seconds
25 gems installed
安装成功后,查看版本号:
$ jekyll -v
jekyll 3.8.5
3.Jekyll常用命令
Jekyll安装好后,就可以在命令行中使用Jekyll命令了,有以下用法:
$ jekyll build
# => 当前文件夹中的内容将会生成到 ./site 文件夹中
$ jekyll build --destination <destination>
# => 当前文件夹中的内容将会生成到目标文件夹<destination>中
$ jekyll build --source <source> --destination <destination>
# => 指定源文件夹<source>中的内容将会生成到目标文件夹<destination>中
$ jekyll build --watch
# => 当前文件夹中的内容将会生成到 ./site 文件夹中,
# 查看改变,并且自动再生成
build的时候如遇以下错误,则是缺少依赖插件包:
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/!
jekyll 3.8.5 | Error: jekyll-paginate
输入以下命令安装:
$ gem install jekyll-paginate
Jekyll 同时也集成了一个开发用的服务器,可以让你使用浏览器在本地进行预览。
$ jekyll serve
# => 一个开发服务器将会运行在 http://localhost:4000/
$ jekyll serve --detach
# => 功能和`jekyll serve`命令相同,但是会脱离终端在后台运行。
# 如果你想关闭服务器,可以使用`kill -9 1234`命令,"1234" 是进程号(PID)
# 如果你找不到进程号,那么就用`ps aux | grep jekyll`命令来查看,然后关闭
$ jekyll serve --watch
# => 和`jekyll serve`相同,但是会查看变更并且自动再生成
还有一些可以配置的配置选项.很多配置选项既可以在命令行中作为标识(flags)设定,也可以在源文件根目录中的 _config.yml
文件中进行设定。Jekyll 会自动加载这些配置。比如你在你的 _config.yml
文件中添加了下面几行:
destination: _deploy
source: _source
那么就等价于执行了以下两条命令:
$ jekyll build
$ jekyll build --source _source --destination _deploy
详细配置见官网配置列表:https://www.jekyll.com.cn/docs/configuration/
标签:jekyll,Fetching,rvm,Jekyll,MAC,usr,gem,搭建 来源: https://blog.csdn.net/chen_changying/article/details/88093559