Tag Archives: extention

ubuntu 12.04安装jekyll

ubuntu版本

$ cat /etc/issue
Ubuntu 12.04 LTS \n \l

$ uname -a
Linux ubuntu 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Linux

安装ruby和jekyll

没有gem就安装。

调整为taobao源

$ gem sources --remove https://rubygems.org/
$ gem sources --remove http://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l
\*** CURRENT SOURCES ***

https://ruby.taobao.org
# 请确保只有 ruby.taobao.org

安装rvm和ruby:

$ sudo apt-get install curl
$ sudo gem install rvm
$ \curl -sSL https://get.rvm.io | bash
$ source /home/user/.rvm/scripts/rvm
$ rvm install ruby-2.1.2
$ rvm use ruby-2.1.2

安装js runtime:

$ sudo apt-get install nodejs
$ gem install execjs

安装jekyll:

$ gem install jekyll

备注: 由于apt-get安装的软件可能版本相对较老,因此推荐用rvm安装ruby。

可能遇到的一些问题

ERROR: Failed to build gem native extension

错误情况:

$ sudo gem install jekyll
Fetching: liquid-2.6.1.gem (100%)
Fetching: kramdown-1.4.1.gem (100%)
Fetching: mercenary-0.3.4.gem (100%)
Fetching: safe_yaml-1.0.3.gem (100%)
Fetching: colorator-0.1.gem (100%)
Fetching: yajl-ruby-1.1.0.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing jekyll:
        ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
        from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from extconf.rb:1:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/yajl-ruby-1.1.0 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/yajl-ruby-1.1.0/ext/yajl/gem_make.out

原因: ruby版本过老,apt-get install ruby的版本一般是1.8,请使用rvm安装2.1版本的ruby;哪些最新可用版本请用rvm list known查看。

Could not find a JavaScript runtime

错误情况:

$ jekyll new myblog
/home/user/.rvm/gems/ruby-2.1.2/gems/execjs-2.2.1/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
        from /home/user/.rvm/gems/ruby-2.1.2/gems/execjs-2.2.1/lib/execjs.rb:5:in `<module:ExecJS>'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/execjs-2.2.1/lib/execjs.rb:4:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/coffee-script-2.3.0/lib/coffee_script.rb:1:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/coffee-script-2.3.0/lib/coffee-script.rb:1:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-coffeescript-1.0.0/lib/jekyll-coffeescript.rb:2:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-2.3.0/lib/jekyll/deprecator.rb:46:in `block in gracefully_require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-2.3.0/lib/jekyll/deprecator.rb:44:in `each'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-2.3.0/lib/jekyll/deprecator.rb:44:in `gracefully_require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-2.3.0/lib/jekyll.rb:141:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-2.3.0/bin/jekyll:6:in `<top (required)>'
        from /home/user/.rvm/gems/ruby-2.1.2/bin/jekyll:23:in `load'
        from /home/user/.rvm/gems/ruby-2.1.2/bin/jekyll:23:in `<main>'
        from /home/user/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
        from /home/user/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'

错误原因: 未安装相关js库,请安装nodejs和execjs,请参照以上步骤。

注意事项

安装步骤是针对ubuntu 12.04,其他版本的ubuntu可能有最新的ruby,也可能没有,没经过测试,仅作参考。