LoginSignup
2

More than 5 years have passed since last update.

asdf バージョンマネージャーを使ってElixir+Phoenixの自習

Posted at

きっかけ

仕事でElixir使わないといけなくなったので自習のために何やったらいいだろう?とElixirマスターに相談したら「とりあえずToDoリスト作ってみ」と言われたのでやってみている。
でも、結構、日本語ドキュメントあまりな〜い + お年柄やったことを速攻忘れるので備忘録として残す。

環境

  • Mac OS Sierra 10.12.6
  • 以下インストール済み
    • Homebrew
    • Erlang
    • Elixir
    • Node.js
    • asdf

リンク

http://elixir-lang.org/
http://www.phoenixframework.org/
https://github.com/asdf-vm/asdf

準備

まずはインストールされているElixirの確認

$ asdf list elixir
1.4.1

次にErlangも確認

$ asdf list erlang
19.0

ElixirとErlangのバージョンをセット
フォルダ指定してプロジェクトを作りたいのでlocalを使う。
フォルダ指定なしでHOMEに作っていい場合はglobalを使う

$ asdf local elixir 1.4.1
$ asdf local erlang 19.0

Elixir, Erlang 向けのパッケージ管理ツールのHexをインストールする

$ mix local.hex
Found existing archive: /Users/HOME/.asdf/installs/elixir/1.4.1/.mix/archives/hex-0.17.1.
Are you sure you want to replace it with "https://repo.hex.pm/installs/1.4.0/hex-0.17.1.ez"? [Yn] y
* creating /Users/HOME/.asdf/installs/elixir/1.4.1/.mix/archives/hex-0.17.1

PhoenixFrameworkをインストール

$ mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez
Found existing archive: /Users/HOME/.asdf/installs/elixir/1.4.1/.mix/archives/phx_new.Found existing archive: /Users/HOME/.asdf/installs/elixir/1.4.1/.mix/archives/phx_new.
Are you sure you want to replace it with "https://github.com/phoenixframework/archives/raw/master/phx_new.ez"? [Yn] y

すると.tool-versionsというファイルがフォルダ内に出来上がるので準備は一通り完了。

プロジェクト作成

$ mix phx.new todo
* creating todo/config/config.exs
* creating todo/config/dev.exs
* creating todo/config/prod.exs
* creating todo/config/prod.secret.exs
* creating todo/config/test.exs
* creating todo/lib/todo/application.ex
* creating todo/lib/todo.ex
* creating todo/lib/todo_web/channels/user_socket.ex
* creating todo/lib/todo_web/views/error_helpers.ex
* creating todo/lib/todo_web/views/error_view.ex
* creating todo/lib/todo_web/endpoint.ex
* creating todo/lib/todo_web/router.ex
* creating todo/lib/todo_web.ex
* creating todo/mix.exs
* creating todo/README.md
* creating todo/test/support/channel_case.ex
* creating todo/test/support/conn_case.ex
* creating todo/test/test_helper.exs
* creating todo/test/todo_web/views/error_view_test.exs
* creating todo/lib/todo_web/gettext.ex
* creating todo/priv/gettext/en/LC_MESSAGES/errors.po
* creating todo/priv/gettext/errors.pot
* creating todo/lib/todo/repo.ex
* creating todo/priv/repo/seeds.exs
* creating todo/test/support/data_case.ex
* creating todo/lib/todo_web/controllers/page_controller.ex
* creating todo/lib/todo_web/templates/layout/app.html.eex
* creating todo/lib/todo_web/templates/page/index.html.eex
* creating todo/lib/todo_web/views/layout_view.ex
* creating todo/lib/todo_web/views/page_view.ex
* creating todo/test/todo_web/controllers/page_controller_test.exs
* creating todo/test/todo_web/views/layout_view_test.exs
* creating todo/test/todo_web/views/page_view_test.exs
* creating todo/.gitignore
* creating todo/assets/brunch-config.js
* creating todo/assets/css/app.css
* creating todo/assets/css/phoenix.css
* creating todo/assets/js/app.js
* creating todo/assets/js/socket.js
* creating todo/assets/package.json
* creating todo/assets/static/robots.txt
* creating todo/assets/static/images/phoenix.png
* creating todo/assets/static/favicon.ico

Fetch and install dependencies? [Yn] y
* running mix deps.get
* running mix deps.compile
* running cd assets && npm install && node node_modules/brunch/bin/brunch build

We are all set! Go into your application by running:

    $ cd todo

Then configure your database in config/dev.exs and run:

    $ mix ecto.create

Start your Phoenix app with:

    $ mix phx.server

You can also run your app inside IEx (Interactive Elixir) as:

    $ iex -S mix phx.server

サクッと出来上がり!
mix deps.getなども勝手にやってくれるので楽チン!
あとは最後に書いてある通りプロジェクトのフォルダに移動して、データベース作ってサーバー動かせよ!だそうですのでここからは次回で記録する。

この回のまとめ

  • 公式サイトを見てちまちま自習をしてたらElixirマスターが「そんなことしなくていいよ!もっと簡単にできるよ」と教えてくれて本当に簡単にプロジェクト作成までできた。簡単すぎてあまり書くこともない。
  • ただ、あまりにも簡単すぎて何やってるんだか全くわからなかったので調べ直すとasdfのバージョン管理もそうだけど全体的に日本語ドキュメントが少なすぎ。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2