Winse Blog

走走停停, 熙熙攘攘, 忙忙碌碌, 不知何畏.

在windows操作系统安装jekyll服务

如果windows安装了cygwin,那就不要折腾了,参考本文最后,按照类似linux的安装是最方便简单的了!

参考文档:

我首先把安装过程中参考的链接放上来,下面的操作其实是对他们的一个梳理。

下载 & 安装包

  • MsysGit Git-1.8.3-preview20130601.exe
  • ruby rubyinstaller-1.9.3-p392.exe
  • rubydev DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

安装的路径根据自己的需要进行选择即可。我这里选择的是:

  • C:\Program Files\Git
  • C:\Ruby193
  • C:\rubydev

设置环境变量,并初始化安装rubydev

打开git命令窗口(bash命令行),操作如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Winseliu@WINSE ~
$ export PATH=/c/Ruby193/bin:/c/rubydev/bin:$PATH

Winseliu@WINSE ~
$ cd /c/rubydev/

Winseliu@WINSE /c/rubydev
$ ruby dk.rb  init
[INFO] found RubyInstaller v1.9.3 at C:/Ruby193

Initialization complete! Please review and modify the auto-generated
'config.yml' file to ensure it contains the root directories to all
of the installed Rubies you want enhanced by the DevKit.

Winseliu@WINSE /c/rubydev
$ ruby dk.rb install
[INFO] Updating convenience notice gem override for 'C:/Ruby193'
[INFO] Installing 'C:/Ruby193/lib/ruby/site_ruby/devkit.rb'

安装jekyll

安装的过程并非一路顺风,rubygems的官网好像被禁了。需要更新源。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Winseliu@WINSE /c
$ gem install jekyll
ERROR:  Could not find a valid gem 'jekyll' (>= 0) in any repository
ERROR:  Possible alternatives: jekyll

Winseliu@WINSE /c
$ gem sources --remove http://rubygems.org/
http://rubygems.org/ removed from sources

Winseliu@WINSE /c
$ gem sources -a http://ruby.taobao.org/
http://ruby.taobao.org/ added to sources

Winseliu@WINSE /c
$ gem sources -l
*** CURRENT SOURCES ***

http://ruby.taobao.org/

Winseliu@WINSE /c
$ gem install rack
Fetching: rack-1.5.2.gem (100%)
Successfully installed rack-1.5.2
1 gem installed
Installing ri documentation for rack-1.5.2...
Installing RDoc documentation for rack-1.5.2...

真正安装jekyll

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Winseliu@WINSE /c/rubydev
$ gem install jekyll
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Fetching: classifier-1.3.3.gem (100%)
Fetching: directory_watcher-1.4.1.gem (100%)
Fetching: syntax-1.0.0.gem (100%)
Fetching: maruku-0.6.1.gem (100%)
Fetching: kramdown-1.0.2.gem (100%)
Fetching: yajl-ruby-1.1.0-x86-mingw32.gem (100%)
Fetching: posix-spawn-0.3.6.gem (100%)
Building native extensions.  This could take a while...
Fetching: pygments.rb-0.5.1.gem (100%)
Fetching: highline-1.6.19.gem (100%)
Fetching: commander-4.1.3.gem (100%)
Fetching: safe_yaml-0.7.1.gem (100%)
Fetching: colorator-0.1.gem (100%)
Fetching: jekyll-1.0.3.gem (100%)
Successfully installed fast-stemmer-1.0.2
Successfully installed classifier-1.3.3
Successfully installed directory_watcher-1.4.1
Successfully installed syntax-1.0.0
Successfully installed maruku-0.6.1
Successfully installed kramdown-1.0.2
Successfully installed yajl-ruby-1.1.0-x86-mingw32
Successfully installed posix-spawn-0.3.6
Successfully installed pygments.rb-0.5.1
Successfully installed highline-1.6.19
Successfully installed commander-4.1.3
Successfully installed safe_yaml-0.7.1
Successfully installed colorator-0.1
Successfully installed jekyll-1.0.3
14 gems installed
Installing ri documentation for fast-stemmer-1.0.2...
Installing ri documentation for classifier-1.3.3...
Installing ri documentation for directory_watcher-1.4.1...
Installing ri documentation for syntax-1.0.0...
Installing ri documentation for maruku-0.6.1...
Couldn't find file to include 'MaRuKu.txt' from lib/maruku.rb
Installing ri documentation for kramdown-1.0.2...
Installing ri documentation for yajl-ruby-1.1.0-x86-mingw32...
Installing ri documentation for posix-spawn-0.3.6...
Installing ri documentation for pygments.rb-0.5.1...
Installing ri documentation for highline-1.6.19...
Installing ri documentation for commander-4.1.3...
Installing ri documentation for safe_yaml-0.7.1...
Installing ri documentation for colorator-0.1...
Installing ri documentation for jekyll-1.0.3...
Installing RDoc documentation for fast-stemmer-1.0.2...
Installing RDoc documentation for classifier-1.3.3...
Installing RDoc documentation for directory_watcher-1.4.1...
Installing RDoc documentation for syntax-1.0.0...
Installing RDoc documentation for maruku-0.6.1...
Couldn't find file to include 'MaRuKu.txt' from lib/maruku.rb
Installing RDoc documentation for kramdown-1.0.2...
Installing RDoc documentation for yajl-ruby-1.1.0-x86-mingw32...
Installing RDoc documentation for posix-spawn-0.3.6...
Installing RDoc documentation for pygments.rb-0.5.1...
Installing RDoc documentation for highline-1.6.19...
Installing RDoc documentation for commander-4.1.3...
Installing RDoc documentation for safe_yaml-0.7.1...
Installing RDoc documentation for colorator-0.1...
Installing RDoc documentation for jekyll-1.0.3...

创建新博客

(2014年3月19日更新 Cygwin)

建立新的本地测试文件夹

1
2
3
4
5
6
7
8
9
Administrator@winseliu /cygdrive/c/Users/Administrator/target
$ rm -rf export

Administrator@winseliu /cygdrive/c/Users/Administrator/target
$ jekyll new export
New jekyll site installed in /cygdrive/c/Users/Administrator/target/export.

Administrator@winseliu /cygdrive/c/Users/Administrator/target
$ cd export/

修改配置_config.yml

1
2
3
name: Your New Jekyll Site
markdown: rdiscount
pygments: false

启动服务

1
2
3
4
5
6
7
8
9
10
11
12
Administrator@winseliu /cygdrive/c/Users/Administrator/target/export
$ jekyll serve --trace -w -P 8000
Configuration file: /cygdrive/c/Users/Administrator/target/export/_config.yml
            Source: /cygdrive/c/Users/Administrator/target/export
       Destination: /cygdrive/c/Users/Administrator/target/export/_site
      Generating... done.
 Auto-regeneration: enabled
[Listen warning]:
  Listen will be polling for changes. Learn more at https://github.com/guard/listen#polling-fallback.

    Server address: http://0.0.0.0:8000
  Server running... press ctrl-c to stop.

注意点

出现编码问题

参考:http://www.duzengqiang.com/blog/post/979.html

文件在对应的文件夹下: C:\Ruby193\lib\ruby\gems\1.9.1\gems\jekyll-1.0.3\lib\jekyll\convertible.rb

1
2
-        self.content = File.read(File.join(base, name))
+        self.content = File.read(File.join(base, name), :encoding=>"utf-8")

(2014-3-13更新)重装系统后,jekyll-1.3.1版本的代码不同了,修改如下:

1
2
def read_yaml(base, name, opts = {:encoding=>"utf-8"})
  begin

OR

http://www.dewen.org/q/5893

要指定文件的编码格式 在文件开头加上 # -*- coding:utf-8 -*-

指定运行环境的编码 使用 ruby --encoding=utf-8

启动

1
2
3
4
5
Winseliu@WINSE ~
$ cd /c/Users/Winseliu/Documents/GitHub/winse.github.com/

Winseliu@WINSE ~/Documents/GitHub/winse.github.com (master)
$ jekyll serve --trace -w

然后访问 http://localhost:4000 即可。

本地调试

  • ruby使用puts输出,可以用来打印调试!
  • 在本地免不了要写一些中文名的文件,可以直接增加try-catch(post.rb#self.valid, cleaner.rb#existing_files)!但网上有讲ruby2.0可以处理中文文件名了!
  • 当然本地调试可以通过修改_config.xml的exclude排除掉,修改好需要发布时再修改为英文文件名即可!

post.rb

1
2
3
4
5
6
7
8
def self.valid?(name)
begin
  name =~ MATCHER
rescue => err
  puts err
  puts name
end
end

编写文件头需要注意的地方;

诡异的jekyll空格

忽然想起之前看过的一篇博客,这篇文章中说起“YAML格局默认是:参数+:+空格,若是忘怀写空格描画编译报错。”。
在这里,恰是因为忘怀了空格导致了HTML文件无法生成的题目。

maruku的不足

使用rdiscount ( gem install rdiscount ) 替换。

参考


WINDOW直接在cygwin中安装jekyll

  1. 使用cygwin setup.exe安装ruby1.9(安装2.0的报编码的错),以及libyaml,最好也把git安装一下。配置环境变量。
  2. 使用gem install jekyll安装。
  3. 安装依赖gem install rdiscount
  4. 启动jekyll serve --trace -w

由于cygwin下默认是utf8编码,并且已经有了linux的各种命令,安装起来很简单。


win10预览版-cygwin32部署octopress(更新于2015-04-18)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
winse@Lenovo-PC ~
$ ruby -v
ruby 2.0.0p598 (2014-11-13) [i386-cygwin]

LC_CTYPE=C.BINARY gem sources -a https://ruby.taobao.org/
LC_CTYPE=C.BINARY gem install bundler
LC_CTYPE=C.BINARY gem install rdiscount

cd winsegit/octopress/
bundle install
rake preview

#去掉watch功能,ruby我不懂啊,实时更新也不是很需要
vi Rakefile
#  jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build --watch")
#  compassPid = Process.spawn("compass watch")
  jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build ")

(更新2017-7-8,通过setup.exe更新了cygwin)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Ruby安装后运行失败:
winse@Lenovo-PC ~
$ ruby -v
C:/cygwin/bin/ruby.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

winse@Lenovo-PC ~
$ cygcheck /bin/ruby
C:\cygwin\bin\ruby.exe
  C:\cygwin\bin\cygruby220.dll
    C:\cygwin\bin\cygwin1.dll
      C:\Windows\system32\KERNEL32.dll
        C:\Windows\system32\ntdll.dll
        C:\Windows\system32\KERNELBASE.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-handle-l1-1-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-synch-l1-2-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-timezone-l1-1-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-string-l1-1-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-util-l1-1-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-profile-l1-1-0.dll
        C:\Program Files\MiKTeX 2.9\miktex\bin\api-ms-win-core-console-l1-1-0.dll
    C:\cygwin\bin\cyggmp-10.dll
    C:\cygwin\bin\cyggcc_s-1.dll
    C:\cygwin\bin\cygssp-0.dll
    C:\Windows\system32\USER32.dll
      C:\Windows\system32\GDI32.dll
cygcheck: track_down: could not find cygcrypt-0.dll

winse@Lenovo-PC ~
$ cygcheck.exe -c | grep Incomplete
libcrypt0                            1.4-1                        Incomplete
...

通过setup.exe重新安装libcrypt0, ruby-devel, rake 10.4.2

winse@Lenovo-PC ~
$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 9808) [i386-cygwin]
last_commit=ruby 2.2.6

$ gem install bigdecimal

winse@Lenovo-PC ~/winsegit/octopress
$ bundle install
Fetching gem metadata from https://ruby.taobao.org/..........

2017-10-29 11:07:45 (win10-2017-appx-ubuntu)

不要服用cygwin的用户目录了,权限和软链的方式都不同了。很麻烦,不如另起炉灶!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
用powershell管理员权限,修改就旧系统的文件属性:
PS E:\winsegit\octopress> cacls *.* /T /G Everyone:F

sudo apt-get update
sudo apt-get install ruby-bundler
sudo apt-get install ruby-dev
sudo apt-get install make
sudo apt-get install gcc
bundle install

sudo gem update
sudo gem uninstall rake
sudo gem install rake -v 10.5.0
sudo apt-get install nodejs
   
rake preview

winse@DESKTOP-ADH7K1Q:~/winsegit/octopress$ rake preview
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
Starting to watch source with Jekyll and Compass. Starting Rack on port 4000
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
/usr/lib/ruby/vendor_ruby/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /mnt/c/Windows/System32 in PATH, mode 040777
/var/lib/gems/2.3.0/gems/liquid-2.6.1/lib/liquid/htmltags.rb:43: warning: key "index0" is duplicated and overwritten on line 46
[2017-10-29 22:48:09] INFO  WEBrick 1.3.1
[2017-10-29 22:48:09] INFO  ruby 2.3.1 (2016-04-26) [x86_64-linux-gnu]
[2017-10-29 22:48:09] INFO  WEBrick::HTTPServer#start: pid=39 port=4000
Configuration file: /mnt/e/winsegit/octopress/_config.yml
            Source: source
       Destination: public
      Generating...
                    done.

–END