LoginSignup
13
11

More than 3 years have passed since last update.

macOS Catalina(10.15.5)にasdfでElixirをインストールする

Last updated at Posted at 2019-11-04

はじめに

  • % brew install elixir でインストールしたElixirで楽しんでいましたが、asdfでインストールするのがいいらしいといろいろな人から聞いていました
  • HomebrewでインストールしたElixirのままでもまあいいかとおもっていたのですが、ちょっとNervesという「Nerves is young, but already powers rock-solid shipping industrial products!」(若くてナウいヤツ)を試してみようといろいろみていたら、そちらでもasdfでのインストールが薦められていたので切り替えることにしました
  • この記事のポイントは入手可能なバージョンの調べ方です
    • % asdf list all erlang
    • % asdf list all elixir

参考にした記事 |> ありがとうございます!

手順

1. Command Line Toolsのインストール


% xcode-select --install

2. Homebrewのインストール

  • Homebrewの先頭のほうに書いてあるスクリプトをターミナルに貼り付けて実行してください
% /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

すでにHomebrewをインストール済の場合 -> 更新

% brew update
% brew upgrade

HomebrewElixirをインストールしていた場合 -> ErlangElixirをアンインストール


% brew uninstall --force erlang elixir

3. asdfのインストールとプラグインのインストール

  • 公式の説明はこちら
  • 2020/05/28時点の情報です
  • 記事が古い場合には、公式をご参照ください
  • 以下、Homebrewasdfをインストールする手順を転載しておきます
  • macOS Catalina(10.15.5)はzshが標準ですので、zshの手順を書いています
% brew install asdf

~/.zshrcに以下を書き足す

~/.zshrc
. $(brew --prefix asdf)/asdf.sh

if type brew &>/dev/null; then
  FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH

  autoload -Uz compinit
  compinit
fi
% source ~/.zshrc
% brew install coreutils automake autoconf openssl libyaml readline libxslt libtool unixodbc unzip curl unixodbc fop
% asdf plugin-add erlang
% asdf plugin-add elixir

補足

4. Erlangのインストール

% asdf install erlang 23.0.1
  • % asdf list all erlang
  • 手に入れることができるバージョンを調べることができます

補足(情報古い)

  • 当初% asdf install erlang 22.1 とやっていたのですが以下のエラーがでていました
 * documentation  : 
 *                  fop is missing.
 *                  Using fakefop to generate placeholder PDF files.

Build failed.
/bin/sh: line 1: 50830 Segmentation fault: 11  erlc -W +debug_info -DUSE_ESOCK=true +inline +warn_unused_import +warn_export_vars -Werror -o../ebin hipe_rtl_arch.erl
make[3]: *** [../ebin/hipe_rtl_cleanup_const.beam] Error 139
make[3]: *** Waiting for unfinished jobs....
make[3]: *** [../ebin/hipe_rtl_arch.beam] Error 139
/bin/sh: line 1: 50813 Segmentation fault: 11  erlc -W +debug_info -DUSE_ESOCK=true +inline +warn_unused_import +warn_export_vars -Werror -o../ebin hipe_rtl_binary.erl
make[3]: *** [../ebin/hipe_rtl_liveness.beam] Error 139
make[3]: *** [../ebin/hipe_rtl_binary.beam] Error 139
make[2]: *** [opt] Error 2
make[1]: *** [opt] Error 2
make: *** [secondary_bootstrap_build] Error 2
  • Build Fails on macOS 10.15 Catalina という記事をみつけまして、% asdf install erlang 22.1.4だと「worked for me」のようでErlangのバージョンに強いこだわりがあるわけではないので私も「worked for me」となりました

5. Elixirのインストール

% asdf install elixir 1.10.3-otp-23
  • % asdf list all elixir
  • 手に入れることができるバージョンを調べることができます

6. バージョンを指定

% asdf global erlang 23.0.1
% asdf global elixir 1.10.3-otp-23

7. Congratulations!!!

% iex
Erlang/OTP 23 [erts-11.0.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Interactive Elixir (1.10.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> "Hello, world"
"Hello, world"
iex(2)> 1 + 1
2
iex(3)> 1..100 |> Enum.filter(&(&1 < 5))
[1, 2, 3, 4]
13
11
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
13
11