windows安裝jekyll
步驟:
- 安裝 Ruby
- 安裝 DevKit
- 安裝 Jekyll
1、安裝 Ruby
在Windows上使用RubyInstaller安裝比較方便,去Ruby官網下載最新版本的RubyInstaller。注意32位和64位版本的區分。
下載官網推薦的ruby+devkit
安裝:使用默認路徑即可,避免出錯;勾選添加到PATH,就不用手動添加環境變量了
安裝完成如圖:
這里需要勾選安裝msys2,后面安裝gem和jekyll時會用到:
2. 安裝RubyGems
Windows中下載ZIP格式比較方便,下載后解壓到任意路徑。進入解壓目錄,打開cmd,輸入以下命令:
ruby setup.rb
3. 安裝Jekyll
在cmd中輸入:
gem install jekyll
4. 安裝jekyll-paginate
在cmd中輸入:
gem install jekyll-paginate
5. 驗證安裝完成
在cmd中輸入:
jekyll -v
輸出版本說明安裝完成
6. 安裝bundler
在cmd中輸入:
gem install bundler
驗證:cmd輸入:
bundler -v
7. 新建博客模板
安裝完成,我們可以用jekyll命令創建一個博客模板,進入一個目錄,打開命令行執行:
jekyll new testblog
cd testblog
jekyll serve
在瀏覽器輸入http://127.0.0.1:4000/即可瀏覽剛剛創建的blog
遇到問題及解決
1. gem install jekyll時報錯,而且還是亂碼!
C:\User>gem install jekyll
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
ERROR: Error installing jekyll:
ERROR: Failed to build gem native extension.
current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
C:/Ruby25-x64/bin/ruby.exe -r ./siteconf20180308-3672-ueo7ea.rb extconf.rb
creating Makefile
current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
make "DESTDIR=" clean
'make' �����ڲ����ⲿ���Ҳ���ǿ����еij���
�����������
current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
make "DESTDIR="
'make' �����ڲ����ⲿ���Ҳ���ǿ����еij���
�����������
make failed, exit code 1
Gem files will remain installed in C:/Ruby24-x64/bin/ruby_builtin_dlls/Ruby24-x6
4/lib/ruby/gems/2.4.0/gems/http_parser.rb-0.6.0 for inspection.
Results logged to C:/Ruby24-x64/bin/ruby_builtin_dlls/Ruby24-x64/lib/ruby/gems/2
.4.0/extensions/x64-mingw32/2.4.0/http_parser.rb-0.6.0/gem_make.out
參考oneclick/rubyinstaller2的 issue #98。
首先cmd中輸入:
chcp 850
切換編碼之后安裝:
gem install jekyll
下面是報錯:
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
ERROR: Error installing jekyll:
ERROR: Failed to build gem native extension.
current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
C:/Ruby25-x64/bin/ruby.exe -r ./siteconf20180308-3672-ueo7ea.rb extconf.rb
creating Makefile
current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
make "DESTDIR=" clean
'make' 不是內部或外部命令,也不是可運行的程序或批處理文件。
current directory: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/http_parser.rb-0.6.0/ext/ruby_http_parser
make "DESTDIR="
'make' 不是內部或外部命令,也不是可運行的程序或批處理文件。
make failed, exit code 1
Gem files will remain installed in C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/http_p
arser.rb-0.6.0 for inspection.
Results logged to C:/Ruby25-x64/lib/ruby/gems/2.5.0/extensions/x64-mingw32/2.5.0
/http_parser.rb-0.6.0/gem_make.out
原來是沒有make指令,上面的步驟其實已經安裝了msys2,所以不會出現問題。對於沒有勾選的童鞋,可以在cmd中輸入下面命令來安裝:
ridk install
安裝完成之后再次安裝jekyll和jekyll-paginate就ok了。
2. jekyll serve啟動報錯
首先看看是不是把serve
打成了server
Incremental build: disabled. Enable with --incremental
Generating...
jekyll 3.7.3 | Error: Permission denied @ rb_sysopen - C:/Users/username/NTUSER.DAT
這是因為jekyll默認使用4000端口,而4000是FoxitProtect(福昕閱讀器的一個服務)的默認端口。網上有教程說kill掉FoxitProtect的進程,但是我覺得首先這個比較麻煩,其次重啟計算機時FoxitProtect是默認啟動的,除非關閉這個服務,這樣又可能帶來其他問題。所以最簡單的辦法還是指定端口:
jekyll serve -P 5555
參考鏈接: