LoginSignup
13
4

More than 3 years have passed since last update.

asdfでErlangをインストールする場合の留意点

Last updated at Posted at 2019-11-13

Elixirの動作環境をasdfで構築していた際に気づいた点。

最初に結論

Elixirを動作させるためには、事前にErlangのインストールが必要です。
しかし、asdfのインストール手順に書かれている手順でインストールされるライブラリだけでは、Erlangのコンパイルエラーは発生しないものの、動作制限がある状態となっていました。
例:observerを起動できない。

Erlangの動作制限がない状態にするには、「asdf-erlang」に記載されている内容に従って、asdfでErlangをインストールする前に必要なライブラリをインストールしておく必要があります。

Ubuntu(Ubuntu 18.04)での場合の例

以下、「Ubuntu 18.04」を例にして説明します。

ビルドは通っているが動作制限あり

asdfのインストール内容に従ってインストールしたライブラリだけでは、Erlangが本来必要とするライブラリが不足しています。

例えば、「:observer.start()」を実行しても、ライブラリが足りずに起動できません。

$ iex
Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe]

Interactive Elixir (1.9.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :observer.start()

13:45:56.837 [error] ERROR: Could not find 'wxe_driver.so' in: /home/rk/.asdf/installs/erlang/22.0.4/lib/wx-1.8.8/priv

{:error,
 {{:load_driver, 'No driver found'},
  [
    {:wxe_server, :start, 1, [file: 'wxe_server.erl', line: 65]},
    {:wx, :new, 1, [file: 'wx.erl', line: 115]},
    {:observer_wx, :init, 1, [file: 'observer_wx.erl', line: 107]},
    {:wx_object, :init_it, 6, [file: 'wx_object.erl', line: 372]},
    {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}
  ]}}
iex(2)>

asdf-erlangに必要なライブラリのインストール

こちらの内容に従い、Erlangに必要なライブラリをインストールします。
https://github.com/asdf-vm/asdf-erlang#before-asdf-install

Ubuntuの場合は、こちらのURLの内容を参照します。
https://github.com/asdf-vm/asdf-erlang#ubuntu-and-debian

対象は以下でした。

  • build-essential
  • autoconf
  • m4
  • libncurses5-dev
  • libwxgtk3.0-dev
  • libgl1-mesa-dev
  • libglu1-mesa-dev
  • libpng-dev
  • libssh-dev
  • unixodbc-dev
  • xsltproc
  • fop

これをaptでインストールします。

# apt install build-essential autoconf m4 libncurses5-dev libwxgtk3.0-dev libgl1-mesa-dev libglu1-mesa-dev libpng-dev libssh-dev unixodbc-dev xsltproc fop
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了

~(略)~

Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...

done.
done.
hicolor-icon-theme (0.17-2) のトリガを処理しています ...
fontconfig (2.12.6-0ubuntu2) のトリガを処理しています ...
mime-support (3.60ubuntu1) のトリガを処理しています ...
desktop-file-utils (0.23-1ubuntu3.18.04.2) のトリガを処理しています ...
# 

既存のerlangをアンインストール後に再インストールする

必要なライブラリのインストールが完了したので、Erlangを再インストールします。
asdf uninstall erlang <バージョン>でアンインストールした後で、もう一度asdf install erlang <バージョン>で再インストールします。
再インストール後、erlが起動することを確認します。

$ asdf current
elixir         1.9.4-otp-22 (set by /home/rk/.tool-versions)
erlang         22.0.4   (set by /home/rk/.tool-versions)
$ 
$ asdf uninstall erlang 22.0.4
asdf_22.0.4 /home/rk/.asdf/installs/erlang/22.0.4
The asdf_22.0.4 build has been deleted
The installation "/home/rk/.asdf/installs/erlang/22.0.4" has been deleted
$ 
$ asdf install erlang 22.0.4
Extracting source code
Building Erlang/OTP 22.0.4 (asdf_22.0.4), please wait...
APPLICATIONS DISABLED (See: /home/rk/.asdf/plugins/erlang/kerl-home/builds/asdf_22.0.4/otp_build_22.0.4.log)
 * jinterface     : No Java compiler found

DOCUMENTATION INFORMATION (See: /home/rk/.asdf/plugins/erlang/kerl-home/builds/asdf_22.0.4/otp_build_22.0.4.log)
 * documentation  : 
 *                  xmllint is missing.
 *                  Using fakefop to generate placeholder PDF files.

Erlang/OTP 22.0.4 (asdf_22.0.4) has been successfully built
Installing Erlang/OTP 22.0.4 (asdf_22.0.4) in /home/rk/.asdf/installs/erlang/22.0.4...
You can activate this installation running the following command:
. /home/rk/.asdf/installs/erlang/22.0.4/activate
Later on, you can leave the installation typing:
kerl_deactivate
Cleaning up compilation products for 
Cleaned up compilation products for  under /home/rk/.asdf/plugins/erlang/kerl-home/builds

Erlang 22.0.4 has been installed. Activate globally with:

    asdf global erlang 22.0.4

Activate locally in the current folder with:

    asdf local erlang 22.0.4

$ 
$ asdf global erlang 22.0.4
$ 
$ erl
Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe]

Eshell V10.4.3  (abort with ^G)
1> 
User switch command
 --> q
$ 
$ asdf current
elixir         1.9.4-otp-22 (set by /home/rk/.tool-versions)
erlang         22.0.4   (set by /home/rk/.tool-versions)
$ 

observerの起動確認

Erlangの再インストール後、改めて「:observer.start()」を実行します。
今度は「:ok」が表示されて、observerが起動しました。

r$ iex
Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe]

Interactive Elixir (1.9.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :observer.start()
Gtk-Message: 14:19:14.976: Failed to load module "canberra-gtk-module"
                                                                      :ok
iex(2)> 

終わりに

asdf経由でインストールしていたElixirは半年ぐらい触っていたのですが、Erlang側の機能を利用するまで気付くことができませんでした。
asdfのプラグインを利用すると簡単にインストールができる反面、どのようにしてインストールされているのかについては意識が向かなくなりがちです。
今後は、利用するプラグインのGitHubページには目を通すようにしていこうと思います。

13
4
1

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
4