LoginSignup
4
5

More than 5 years have passed since last update.

Elixirの環境をセットアップする

Last updated at Posted at 2017-10-29

何をするの

ちょっとElixirを触ってみたくなったので、環境構築を備忘録をつけつつ行います。
言語のバージョン管理はanyenvで行なっているため、単一バージョンが欲しい方は別の記事を読んだ方が良いかもしません。

環境

MacBook Pro (15-inch, 2016)
macOS High Sierra

セットアップ

Install erlang

Elixirを動かすためにErlangの環境を構築する必要がある。

Erlangの仮想マシン (BEAM) 上で動作するコンピュータプログラミング言語である。ElixirはErlangで実装されているため、分散システム、耐障害性、ソフトリアルタイムシステム等の機能を使用することができるが、拡張機能として、マクロを使ったメタプログラミング、そしてポリモーフィズムなどのプログラミング・パラダイムもプロトコルを介して実装されている。

wikipedia

Erlangにはインストールコマンドがないので、ビルドを自分で行います。

# install erlanv
❯ anyenv install erlenv

# Erlangのビルドに依存しそうなものをbrewで入れる
❯ brew install unixodbc wxmac fop
❯ brew install kerl
❯ kerl list releases
R10B-0 R10B-10 R10B-1a R10B-2 R10B-3 R10B-4 R10B-5 R10B-6 R10B-7 R10B-8 R10B-9 R11B-0 R11B-1 R11B-2 R11B-3 R11B-4 R11B-5 R12B-0 R12B-1 R12B-2 R12B-3 R12B-4 R12B-5 R13A R13B01 R13B02-1 R13B02 R13B03 R13B04 R13B R14A R14B01 R14B02 R14B03 R14B04 R14B R14B_erts-5.8.1.1 R15B01 R15B02 R15B02_with_MSVCR100_installer_fix R15B03-1 R15B03 R15B R16A_RELEASE_CANDIDATE R16B01 R16B02 R16B03-1 R16B03 R16B 17.0-rc1 17.0-rc2 17.0 17.1 17.3 17.4 17.5 18.0 18.1 18.2 18.2.1 18.3 19.0 19.1 19.2 19.3 20.0 20.1
Run '/usr/local/bin/kerl update releases' to update this list from erlang.org

# 最新版をbuild
❯ kerl build 20.1 20.1
...
Erlang/OTP 20.1 (20.1) has been successfully built

❯ kerl install 20.1 $ANYENV_ROOT/envs/erlenv/releases/20.1

❯ erl --version
Erlang/OTP 20 [erts-9.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.1  (abort with ^G)
1>

ここまででErlangがインストールできました。

Install Elixir

Elixirをインストールしていきます。

❯ anyenv install exenv
❯ exenv install -l
Available versions:
  1.5.2/Docs.zip
  1.5.2
  1.5.1/Docs.zip
  1.5.1
...
# 最新の1.5.2をインストールする
❯ exenv install 1.5.2
❯ exenv global 1.5.2
❯ exenv rehash
❯ elixir -v
Erlang/OTP 20 [erts-9.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false]

Elixir 1.5.2

Interactive mode

iex(1)> 100 + 50
150
iex(2)> "Hello" <> "World"
"HelloWorld"

Run Script

cat hello_world.exs
IO.puts "Hello World from Elixir"
❯ elixir hello_world.exs
Hello World from Elixir

ついでに

パッケージ管理ツールのhexとフレームワークのPhoenixをインストールしておきます。

PhoenixはRuby on Railsに該当します。

Phoenix プロジェクトの生成はElixir付随のmixコマンドで行います。

❯ mix local.hex
Found existing entry: /Users/ryota/.mix/archives/hex-0.17.1
Are you sure you want to replace it with "https://repo.hex.pm/installs/1.5.0/hex-0.17.1.ez"? [Yn] Y
* creating /Users/ryota/.mix/archives/hex-0.17.1
❯ mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez
Found existing entry: /Users/ryota/.mix/archives/phoenix_new
Are you sure you want to replace it with "https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez"? [Yn] Y
* creating /Users/ryota/.mix/archives/phoenix_new

これで、webアプリケーションを作成する準備は完了です。

4
5
0

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
4
5