問題提起
年末にOSをクリーンインストールした際に、
Octopressのライブラリ一式もふっとんだので設定し直したい。
rubyのライブラリがグローバルに入るのは嫌だなぁと思って、とりあえずAmazonLinuxで試してみましたが、色々トラブったのでメモっておきます。
前提
- Octopress2.0
- AmazonLinux(2014.09.1)
- ソース一式はBitbucketで保管されてる。
- Deploy先はGithubPage
Octopressの簡単な説明
Jekyllをベースにした静的ブログジェネレータ
似たようなものでMiddlemanとかHugoとかがある。
メリット:
- 機能・デザインテンプレートが充実してる
- GithubPageなどへのデプロイが楽。
デメリット:
- ビルドがけっこう遅い。
- rubyの依存解決がめんどい。
- 記事が全て同一フォルダに置かれるので管理しにくい。
結構デメリットが大きいですが、デザインを設定してしまって変えるのがめんどくさいので、惰性で続けています。
手順
まずはgit入れたりリポジトリ落として来たりする。
以下、ターミナルでoctopressフォルダにいる場合。
gem install
$ (sudo) gem install bundler
# octopressのGemfileを見て必要なライブラリをインストールする。
# pathオブションを指定するとそのディレクトリに依存ライブラリが入るらしい。
# Cabalでいうsandboxみたいなものと思ってる。
$ bundle install --path vendor/bundle
# 指定したpathの情報は.bundle/configに入るらしい
# 以降そのディレクトリでは'bundle exec'を頭につけると各種コマンドが使える。
普通ならこれでinstallできるはずなんだけど、、
なんかエラーが出る。
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby2.0 extconf.rb
mkmf.rb can't find header files for ruby at /usr/share/ruby/include/ruby.h
Gem files will remain installed in /home/ec2-user/octopress/vendor/bundle/ruby/2.0/gems/RedCloth-4.2.9 for inspection.
Results logged to /home/ec2-user/octopress/vendor/bundle/ruby/2.0/gems/RedCloth-4.2.9/ext/redcloth_scan/gem_make.out
An error occurred while installing RedCloth (4.2.9), and Bundler cannot
continue.
Make sure that `gem install RedCloth -v '4.2.9'` succeeds before bundling.
rubyのこういうところ嫌い。。。
原因が全くわからないので適当にエラーメッセージでググってみる。
- http://qiita.com/satzz@github/items/0361a7093a57b459e15b
- http://www.xmisao.com/2014/07/06/cannot-load-such-file-mkmf.html
- http://qiita.com/s_osa/items/faf9b892dcd7fa9d8e74
で、足りないものをインストール。
sudo yum -y install ruby-devel
sudo yum -y install gcc-c++
再度bundle install
したらうまく行った。
preview
とりあえずinstallできたのでpreviewしてみる
# bundle execを使うと、グローバルでなくcurrentDirectoryの設定をとってくる。
bundle exec rake preview
Dependency Error: Yikes! It looks like you don't have jekyll-coffeescript or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: 'cannot load such file -- json'
またエラーった。なんかjsonがないって言われる。
gem install json
をやるとグローバルに入ってしまうので、Gemfileにjsonを追加してもっかいinstall
bundle install
# 二回目はpathオプションをつけなくていいらしい。
できた。
curl http://localhost:4000/
でちゃんと応答がある。
4000番portを開けて、ホストマシンからもアクセスしよう。
・・・
繋がらなかった。
どうもrake preview
だと自分自身のアクセスしか受け付けないっぽい。
色々調べたけど、MacのPowってのを使う以外の方法がわからなかった。。。誰か教えてください。
Deploy
bundle exec rake gen_deploy
デプロイ先がないって言われる。そりゃそうですね。。
bundle exec rake setup_github_pages
# ここでページを指定してからgen_deployやると、該当のリポジトリが上書きされるので注意。
# ただ、そこは公開用なので普通は気にしない。
もっかいgen_deployするとうまく行った。
参考URL
http://blog.awairo.net/blog/2013/12/09/reinstall-octopress/
http://morizyun.github.io/blog/octopress-gitpage-minimum-install-guide/