まず、HerokuCLI(herokuを操作するためのコマンド)をインストールします。

devcenter.heroku.com

MacOSインストーラを使ってインストールできます。もちろんHomebrewも使えます。

$ heroku login
heroku-cli: Updating to 6.14.34-1fcf80e... 13.2 MB/13.2 MB
Enter your Heroku credentials:
Email: shigu493@gmail.com
Password: *********
Logged in as shigu493@gmail.com

ログインできました。

$ gem install heroku bundler
ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

パーミッションエラーです。

$ sudo gem install heroku bundler
Password:
Fetching: excon-0.59.0.gem (100%)
Successfully installed excon-0.59.0
Fetching: multi_json-1.11.2.gem (100%)
Successfully installed multi_json-1.11.2
Fetching: heroku-api-0.4.2.gem (100%)
Successfully installed heroku-api-0.4.2
Fetching: public_suffix-3.0.0.gem (100%)
ERROR:  Error installing heroku:
public_suffix requires Ruby version >= 2.1.
Fetching: bundler-1.15.4.gem (100%)
Successfully installed bundler-1.15.4
Parsing documentation for bundler-1.15.4
Installing ri documentation for bundler-1.15.4
1 gem installed

sudoにしたら進みましたが、rubyは2.1.0以上のバージョンが必要だそうです。
下記を参考にrubyのバージョンアップを開始します。

qiita.com

qiita.com

$ brew --version
-bash: brew: command not found

そもそもHomebrewが入っていなかったので、 Macのパッケージ管理システムHomebrewからインストールします。

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
(中略)
==> Next steps:
- Run `brew help` to get started
- Further documentation:
https://docs.brew.sh

インストールが完了しました。
次に、rubyの複数バージョン管理ができるというrbenvを入れます。

$ brew install rbenv ruby-build
==> Installing dependencies for rbenv: autoconf, pkg-config, openssl, ruby-build
==> Installing rbenv dependency: autoconf
==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.sierra.bottle
(中略)
######################################################################## 100.0%
==> Pouring rbenv-1.1.1.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/rbenv/1.1.1: 36 files, 62.9KB

インストール可能のリストを出してみます。

$ rbenv install -l
Available versions:
1.8.5-p52
(中略)
2.1.0
(中略)
topaz-dev

2.1.0がインストールできることを確認して、インストールします。

$ rbenv install 2.1.0
Downloading yaml-0.1.6.tar.gz...
->  https://dqw8nmjcqpjn7.cloudfront.net/7da6971b4bd08a986dd2a61353bc422362bd0edcc67d7ebaac68c95f74182749
Installing yaml-0.1.6...
Installed yaml-0.1.6 to /Users/misato.imaji/.rbenv/versions/2.1.0
ruby-build: use openssl from homebrew
Downloading ruby-2.1.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.0.tar.bz2
Installing ruby-2.1.0...
WARNING: ruby-2.1.0 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.
Installed ruby-2.1.0 to /Users/misato.imaji/.rbenv/versions/2.1.0

インストールできました!
今度こそ…

$ sudo gem install heroku bundler
Password:
ERROR:  Error installing heroku:
public_suffix requires Ruby version >= 2.1.
Successfully installed bundler-1.15.4
Parsing documentation for bundler-1.15.4
1 gem installed

あれ、やっぱり同じエラーです。インストールは完了したはずです。

$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

まだ2.0.0になっていました。
ここでもう一度、macrubyを最新にする方法を確認します。

qiita.com

なるほど、インストールするだけではダメらしいです。

$ sudo cp /usr/bin/ruby /Users/misato.imaji/ruby2.0.0

一旦退避します。

$ rbenv global 2.1.0

globalにしてみても・・・

$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]

やっぱりダメです。変わりません。
rubyのパスは/Users/(ユーザー)/.rbenv/shims/rubyである必要があるそうです。

$ which ruby
/usr/bin/ruby

確かにパスが違います。

$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"

ここで出てくるeval “$(rbenv init -)”を~/.bash_profileに記載すればいいそうです。

$ vim ~/.bash_profile

eval “$(rbenv init -)”をコピってそのまま記載し、:wqで保存してvimを終了します。

$ source ~/.bash_profile

sourceコマンドでbash_profileに記載されたeval “$(rbenv init -)”を実行させます。

$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin16.0]

変わりました!

$ gem install heroku bundler
Fetching: excon-0.59.0.gem (100%)
Successfully installed excon-0.59.0
Fetching: multi_json-1.11.2.gem (100%)
Successfully installed multi_json-1.11.2
Fetching: heroku-api-0.4.2.gem (100%)
Successfully installed heroku-api-0.4.2
(中略)
Done installing documentation for bundler after 6 seconds
14 gems installed

ついにインストールができました。

$ git clone git://github.com/lokka/lokka.git
Cloning into 'lokka'...
remote: Counting objects: 7367, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 7367 (delta 0), reused 4 (delta 0), pack-reused 7358
Receiving objects: 100% (7367/7367), 5.94 MiB | 1.06 MiB/s, done.
Resolving deltas: 100% (4041/4041), done.

lokkaをクローンします。

$ cd lokka

lokkaのディレクトリに移動します。

$ heroku create mysite-by-lokka
This is the legacy Heroku CLI. Please install the new CLI from https://cli.heroku.com
Heroku CLI submits usage information back to Heroku. If you would like to disable this, set     `skip_analytics: true` in /Users/misato.imaji/.config/heroku/config.json
heroku-cli: Installing CLI... 28.19MB/28.19MB
Creating ⬢ mysite-by-lokka... !
▸    Name is already taken

すでにその名前は使われているよ、と言われてしまいました。

$ git push heroku master
fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
$ heroku create (オリジナルの名前)
This is the legacy Heroku CLI. Please install the new CLI from https://cli.heroku.com
Creating ⬢ (オリジナルの名前)... done
https://(オリジナルの名前).herokuapp.com/ | https://git.heroku.com/(オリジナルの名前).git

自分で名前つけるんですね。

そしてこの辺りからは、こちらのサイトを参考にしてセットアップしました。
lokkaのサイト上のコマンドだけだとうまくいかないようです。

d.hatena.ne.jp

$ heroku addons:add heroku-postgresql:dev
This is the legacy Heroku CLI. Please install the new CLI from https://cli.heroku.com
Creating heroku-postgresql:dev on ⬢ stormy-gorge-76709... !
▸    That add-on plan is only available to select users.

あれ、一部のユーザだけってどういうことでしょうか。

$ heroku addons:create heroku-postgresql:dev
This is the legacy Heroku CLI. Please install the new CLI from https://cli.heroku.com
Creating heroku-postgresql:dev on ⬢ stormy-gorge-76709... !
▸    That add-on plan is only available to select users.

やっぱり同じです。

$ heroku addons:create heroku-postgresql
This is the legacy Heroku CLI. Please install the new CLI from https://cli.heroku.com
Creating heroku-postgresql on ⬢ stormy-gorge-76709... free
Database has been created and is available
! This database is empty. If upgrading, you can transfer
! data from another database with pg:copy
Created postgresql-animated-98125 as DATABASE_URL
Use heroku addons:docs heroku-postgresql to view documentation

できました!addを使う必要がありました。

$ heroku addons:add heroku-postgresql
This is the legacy Heroku CLI. Please install the new CLI from https://cli.heroku.com
Creating heroku-postgresql on ⬢ stormy-gorge-76709... free
Database has been created and is available
! This database is empty. If upgrading, you can transfer
! data from another database with pg:copy
Created postgresql-closed-16535 as HEROKU_POSTGRESQL_JADE_URL
Use heroku addons:docs heroku-postgresql to view documentation

HEROKU_POSTGRESQL_JADE_URLがデータベース名のようです。

$ heroku pg:promote HEROKU_POSTGRESQL_JADE_URL
This is the legacy Heroku CLI. Please install the new CLI from https://cli.heroku.com
Ensuring an alternate alias for existing DATABASE_URL... HEROKU_POSTGRESQL_PURPLE_URL
Promoting postgresql-closed-16535 to DATABASE_URL on ⬢ stormy-gorge-76709... done

きました!

$ heroku run rake db:setup
This is the legacy Heroku CLI. Please install the new CLI from https://cli.heroku.com
Running rake db:setup on ⬢ stormy-gorge-76709... up, run.5898 (Free)
(中略)
SQL: (0.002710) SELECT "id", "taggable_id", "taggable_type", "tag_context", "tag_id" FROM "taggings" ORDER BY "id"
SQL: (0.001502) INSERT INTO "taggings" ("id", "taggable_id", "taggable_type", "tag_context", "tag_id") VALUES (1, 1, 'Entry', 'tags', 1)
tagging was successfully created

成功しました。そして…

$ heroku apps:open
This is the legacy Heroku CLI. Please install the new CLI from https://cli.heroku.com

開きました!

これで、Heroku+Lokkaを使ってブログの開設ができました。
openするとデフォルトのID/PWが表示されているので、それを使ってログインし、ID/PWを変更しておきます。

スポンサーリンク