mac 安装 jekyll

Jekyll 介绍

Jekyll 是将纯文本转化为静态网站和博客的项目。官网 描述是这样的:html

`Jekyll` 是一个简单的博客形态的静态站点生产机器。它有一个模版目录,其中包含原始文本格式的文档,经过 `Markdown` (或者 `Textile`) 以及 `Liquid` 转化成一个完整的可发布的静态网站,你能够发布在任何你喜好的服务器上。`Jekyll` 也能够运行在 `GitHub Page` 上,也就是说,你可使用 `GitHub` 的服务来搭建你的项目页面、博客或者网站,并且是彻底免费的。
复制代码

Jekyll 安装

前提

安装 Jekyll 是很是简单的,可是事先你必须作好一些准备工做,确保你的机器上配置了windows

注意:在 windows 下使用 Jekyll,你可使用 Running Jekyll on Windows网站

安装

借助 RubyGems 安装 Jekyll

安装 Jekyll 的最好方式就是使用 RubyGems. 你只须要打开终端输入如下命令就能够安装了:ui

sudo gem install jekyll
复制代码

全部的 Jekyll 的 gem 依赖包都会被自动安装,因此你彻底不用去担忧。若是你在安装中碰到了问题.spa

注意:Mac 须要安装 XcodeCommand-Line Tools了。下载方式 Preferences → Downloads → Componentscode

初始化项目

打开终端找到本身喜欢的目录执行regexp

jekyll new projectName[项目的名称]
复制代码

启动项目

终端指向刚才新初始化的项目目录下,而后执行

jekyll server
复制代码

正常状况下会输出以下内容

Configuration file: /Users/[用户名]/StudyCloud/Blog/myblog/_config.yml
                Source: /Users/[用户名]/StudyCloud/Blog/myblog
           Destination: /Users/[用户名]/StudyCloud/Blog/myblog/_site
     Incremental build: disabled. Enable with --incremental
          Generating... 
                        done in 0.382 seconds.
     Auto-regeneration: enabled for '/Users/lane/StudyCloud/Blog/myblog'
        Server address: http://127.0.0.1:4000/
      Server running... press ctrl-c to stop.
复制代码

启动的服务是监听 4000 端口的。

若是是异常状况,可能会输出以下内容

/usr/local/Cellar/ruby/2.4.3_1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler (LoadError)
	from /usr/local/Cellar/ruby/2.4.3_1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/local/lib/ruby/gems/2.4.0/gems/jekyll-3.6.2/lib/jekyll/plugin_manager.rb:48:in `require_from_bundler'
	from /usr/local/lib/ruby/gems/2.4.0/gems/jekyll-3.6.2/exe/jekyll:11:in `<top (required)>'
	from /usr/local/bin/jekyll:23:in `load'
	from /usr/local/bin/jekyll:23:in `<main>'
lanedeMacBook-Pro:myblog [用户名]$ gem install bundler
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
复制代码

若是异常状况和这个一致,那么问题就好解决了。

  • 一、第一句话是说 bundler 这个包没有找到。既然没有找到那就安装一个,执行命令 sudo gem install bundler.

  • 二、安装完后,火烧眉毛的执行了一下 jekyll server 又发现报错

/usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/resolver.rb:289:in `block in verify_gemfile_dependencies_are_found!': Could not find gem 'minima (~> 2.0)' in any of the gem sources listed in your Gemfile. (Bundler::GemNotFound)
	from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/resolver.rb:257:in `each'
	from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/resolver.rb:257:in `verify_gemfile_dependencies_are_found!'
	from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/resolver.rb:48:in `start'
	from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/resolver.rb:22:in `resolve'
	from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/definition.rb:257:in `resolve'
	from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/definition.rb:170:in `specs'
	from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/definition.rb:237:in `specs_for'
	from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/definition.rb:226:in `requested_specs'
	from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:108:in `block in definition_method'
	from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:20:in `setup'
	from /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler.rb:107:in `setup'
	from /usr/local/lib/ruby/gems/2.4.0/gems/jekyll-3.6.2/lib/jekyll/plugin_manager.rb:50:in `require_from_bundler'
	from /usr/local/lib/ruby/gems/2.4.0/gems/jekyll-3.6.2/exe/jekyll:11:in `<top (required)>'
	from /usr/local/bin/jekyll:23:in `load'
	from /usr/local/bin/jekyll:23:in `<main>'
复制代码
  • 三、这报错愈来愈可怕了。虽然可怕可是总有解决的办法,继续执行 bundle update

  • 四、命令执行完后,再执行 bundle exec jekyll serve 或者 jekyll serve 就 OK 了。

相关文章
相关标签/搜索