Richard in Jekyll 5 minutes

Jekyll Amazon Linux

I wanted to run jekyll on Amazon Linux, it should have been so simple to implement..

The best place to start is checking with Amazon Web Services to find the latest released Amazon Linux AMI here as they are updated regularly, I used ami-70edb016 to launch an instance in eu-west-1 region.

Launch your instance and patch to ensure kernel & packages are latest, powercycle.

$ sudo yum update -y
$ sudo reboot

Install common devtools for Amazon Linux and Ruby (with development packages).

$ sudo yum groupinstall "Development Tools" -y
$ sudo yum install ruby-rdoc ruby-devel -y

Makes life much easier if we install packages from now with RubyGemsthe package manager for Ruby. So now we install Jekyll and Bundler.

$ gem install jekyll bundler

Let’s quickly check we are running the latest version.

$ jekyll --version

Ask Jekyll to magically create us a new site, but we have problems! It’s complaining it doesn’t have io-console installed.

$ jekyll new my-amazing-site
Running bundle install in /home/ec2-user/my-amazing-site...
  Bundler: /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- io/console (LoadError)
  Bundler: from /usr/share/ruby/vendor_ruby/2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  Bundler: from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/shell/basic.rb:2:in `<top (required)>'
  Bundler: from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.14.6/lib/bundler/ui/shell.rb:13:in `initialize'
  Bundler: from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.14.6/lib/bundler/cli.rb:13:in `new'
  Bundler: from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.14.6/lib/bundler/cli.rb:13:in `rescue in start'
  Bundler: from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.14.6/lib/bundler/cli.rb:17:in `start'
  Bundler: from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.14.6/exe/bundle:32:in `block in <top (required)>'
  Bundler: from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.14.6/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
  Bundler: from /home/ec2-user/.gem/ruby/2.0/gems/bundler-1.14.6/exe/bundle:24:in `<top (required)>'
  Bundler: from /home/ec2-user/bin/bundle:23:in `load'
  Bundler: from /home/ec2-user/bin/bundle:23:in `<main>'

So let’s install it now and cleanup before trying again

$ gem install io-console
rm -rf my-amazing-site/

It seems to have worked made the site but for some reason won’t start the webserver

$ cd my-amazing-site/
$ bundle exec jekyll serve
$ bundler: failed to load command: jekyll (/home/ec2-user/bin/jekyll)
LoadError: cannot load such file -- json
  /home/ec2-user/.gem/ruby/2.0/gems/jekyll-3.4.2/lib/jekyll/filters.rb:2:in `require'
  /home/ec2-user/.gem/ruby/2.0/gems/jekyll-3.4.2/lib/jekyll/filters.rb:2:in `<top (required)>'
  /home/ec2-user/.gem/ruby/2.0/gems/jekyll-3.4.2/lib/jekyll.rb:82:in `require'
  /home/ec2-user/.gem/ruby/2.0/gems/jekyll-3.4.2/lib/jekyll.rb:82:in `<module:Jekyll>'
  /home/ec2-user/.gem/ruby/2.0/gems/jekyll-3.4.2/lib/jekyll.rb:36:in `<top (required)>'
  /home/ec2-user/.gem/ruby/2.0/gems/jekyll-3.4.2/exe/jekyll:6:in `require'
  /home/ec2-user/.gem/ruby/2.0/gems/jekyll-3.4.2/exe/jekyll:6:in `<top (required)>'
  /home/ec2-user/bin/jekyll:23:in `load'
  /home/ec2-user/bin/jekyll:23:in `<top (required)>'

After digging and doing some research I found this is a bug caused from existing pre-compiled gems that might not be Ruby compatible, so we just need to remove and force recompilation.

$ gem uninstall ffi
$ echo gem \"json\", \"2.0.2\" >> Gemfile
$ bundle install

And hey presto (finally) it works!

$ bundle exec jekyll serve
$ bundle exec jekyll serve
Configuration file: /home/ec2-user/my-amazing-site/_config.yml
Configuration file: /home/ec2-user/my-amazing-site/_config.yml
            Source: /home/ec2-user/my-amazing-site
       Destination: /home/ec2-user/my-amazing-site/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
                    done in 0.429 seconds.
 Auto-regeneration: enabled for '/home/ec2-user/my-amazing-site'
Configuration file: /home/ec2-user/my-amazing-site/_config.yml
    Server address: http://127.0.0.1:4000/
  Server running... press ctrl-c to stop.