DRYな備忘録

Don't Repeat Yourself.

【Elixir】バージョン管理しつつErlangとElixirをMacにインストールする

just want "Hello, World"?

brew install elixirで、ErlangもElixirも入ります。

参考

qiita.com

Prerequisite

  • JDK installed on your mac
  • brew install wget

Good Bye Elixir, installed via brew

brewで入れたelixirは消す

% brew uninstall elixir
% brew uninstall erlang

バイバイ

kerl for Erlang

github.com

% curl -O https://raw.githubusercontent.com/yrashk/kerl/master/kerl
% chmod a+x kerl
% sudo mv kerl /usr/local/bin
% kerl --help
% kerl list releases

install Erlang 18.0

% kerl build --help
usage: /usr/local/bin/kerl build <release> <build_name>
% kerl build 18.0 18.0-hello
Verifying archive checksum...
Checksum verified (232acb0c278ee05c8d787cbaf6399be5)
Extracting source code
Building Erlang/OTP 18.0 (18.0-hello), please wait...
Erlang/OTP 18.0 (18.0-hello) has been successfully built
% kerl list builds
18.0,18.0-hello

これは、

% ls -la ~/.kerl/builds
total 0
drwxr-xr-x  3 otiai10  staff  102  2  3 14:11 .
drwxr-xr-x  6 otiai10  staff  204  2  3 14:15 ..
drwxr-xr-x  4 otiai10  staff  136  2  3 14:15 18.0-hello
%

ここにビルドが入ってるってだけの意味。これをどっかにinstallして、それをどっかでactivateする

% mkdir -p ~/src/erlang/installations/18.0-hello
% kerl install 18.0-hello ~/src/erlang/installations/18.0-hello
Installing Erlang/OTP 18.0 (18.0-hello) in /Users/otiai10/src/erlang/installations/18.0-hello...
You can activate this installation running the following command:
. /Users/otiai10/src/erlang/installations/18.0-hello/activate
Later on, you can leave the installation typing:
kerl_deactivate
% . /Users/otiai10/src/erlang/installations/18.0-hello/activate
% which erl
/Users/otiai10/src/erlang/installations/18.0-hello/bin/erl
%

asdf

  • kiex <- f**k!
  • exenv <- s**t!
  • asdf <- no other way...

github.com

% cd && git clone https://github.com/HashNuke/asdf.git ~/.asdf
Cloning into '/Users/otiai10/.asdf'...
remote: Counting objects: 1041, done.
remote: Total 1041 (delta 0), reused 0 (delta 0), pack-reused 1041
Receiving objects: 100% (1041/1041), 125.29 KiB | 0 bytes/s, done.
Resolving deltas: 100% (511/511), done.
Checking connectivity... done.
% echo '. $HOME/.asdf/asdf.sh' >> ~/.zshrc
% source .zshrc

install elixir plugin for asdf

% asdf plugin-add elixir https://github.com/HashNuke/asdf-elixir
Cloning into '/Users/otiai10/.asdf/plugins/elixir'...
remote: Counting objects: 142, done.
remote: Total 142 (delta 0), reused 0 (delta 0), pack-reused 141
Receiving objects: 100% (142/142), 14.30 KiB | 0 bytes/s, done.
Resolving deltas: 100% (40/40), done.
Checking connectivity... done.
% asdf plugin-list
elixir

install elixir 1.1.1 via elixir-plugin for asdf

% asdf install elixir 1.1.1
/var/folders/_r/vhm2xvc152s2699tgzr9kr400000gn/T//elixir-precompiled-1.1.1.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   591    0   591    0     0    263      0 --:--:--  0:00:02 --:--:--   263
100 2858k  100 2858k    0     0   168k      0  0:00:16  0:00:16 --:--:--  336k
% asdf which elixir
No version set for elixir
% asdf list elixir
1.1.1
% asdf which elixir
No version set for elixir
% vi .tool-versions # elixir 1.1.1
% asdf reshim elixir
% asdf which elixir
1.1.1
%

Hello, Elixir!!

f:id:otiai10:20160203154727p:plain

固定

まあデフォルトでerlang 18でいいので、.zshrcに以下を追加

# erlang & elixir
. $HOME/src/erlang/installations/18.0-hello/activate
. $HOME/.asdf/asdf.sh

雑感

  • erlangもelixirも、エラーメッセージが不親切で、とりあえず嫌いだなって思いました
  • 動的型付けだし

DRYな備忘録として

追記

stackoverflow.com