Elixirのバージョンを上げる時にちょっと気を付けてねってお話

こんにちは、rickyです。
今日はElixirのバージョンを上げる際に少し気を付けないとハマるポイントがあるのでその対処法について書きます。(2024年3月現在)
以下の記事を参考にPhoenixを最新版にしようとしていました。

https://qiita.com/piacerex/items/01e89435af0f7a454ad2

Phoenix Frameworkの起動には問題がなかったのですが、Elixirを最新版にする際にコケてしまいました。
PreCompiledパッケージのURLからコマンドを読み替えて
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/330568/435f3ad3-6624-0200-ec58-e9e78417479f.png)

> wget https://github.com/elixir-lang/elixir/releases/download/v1.16.2/elixir-otp-26.zip

この状態でelixir --versionをしたところ

> =ERROR REPORT==== 18-Mar-2024::19:54:46.663817 ===
beam/beam_load.c(184): Error loading module 'Elixir.Kernel':
  This BEAM file was compiled for a later version of the runtime system than the current (Erlang/OTP 25).
  To fix this, please re-compile this module with an Erlang/OTP 25 compiler.
  (Use of opcode 182; this emulator supports only up to 180.)

> =ERROR REPORT==== 18-Mar-2024::19:54:46.663849 ===
Loading of /usr/local/bin/../lib/elixir/ebin/Elixir.Kernel.beam failed: badfile

> =ERROR REPORT==== 18-Mar-2024::19:54:46.674068 ===
Loading of /usr/local/bin/../lib/elixir/ebin/elixir_code_server.beam failed: badfile

> =ERROR REPORT==== 18-Mar-2024::19:54:46.674040 ===
beam/beam_load.c(184): Error loading module elixir_code_server:
  This BEAM file was compiled for a later version of the runtime system than the current (Erlang/OTP 25).
  To fix this, please re-compile this module with an Erlang/OTP 25 compiler.
  (Use of opcode 181; this emulator supports only up to 180.)

> =SUPERVISOR REPORT==== 18-Mar-2024::19:54:46.674133 ===
    supervisor: {local,elixir_sup}
    errorContext: start_error
    reason: {'EXIT',
                {undef,
                    [{elixir_code_server,start_link,[],[]},
                     {supervisor,do_start_child_i,3,
                         [{file,"supervisor.erl"},{line,414}]},
                     {supervisor,do_start_child,2,
                         [{file,"supervisor.erl"},{line,400}]},
                     {supervisor,'-start_children/2-fun-0-',3,
                         [{file,"supervisor.erl"},{line,384}]},
                     {supervisor,children_map,4,
                         [{file,"supervisor.erl"},{line,1250}]},
                     {supervisor,init_children,2,
                         [{file,"supervisor.erl"},{line,350}]},
                     {gen_server,init_it,2,
                         [{file,"gen_server.erl"},{line,848}]},
                     {gen_server,init_it,6,
                         [{file,"gen_server.erl"},{line,811}]}]}}
    offender: [{pid,undefined},
               {id,elixir_code_server},
               {mfargs,{elixir_code_server,start_link,[]}},
               {restart_type,permanent},
               {significant,false},
               {shutdown,2000},
               {child_type,worker}]

> =CRASH REPORT==== 18-Mar-2024::19:54:46.674636 ===
  crasher:
    initial call: application_master:init/4
    pid: <0.80.0>
    registered_name: []
    exception exit: {{shutdown,
                      {failed_to_start_child,elixir_code_server,
                       {'EXIT',
                        {undef,
                         [{elixir_code_server,start_link,[],[]},
                          {supervisor,do_start_child_i,3,
                           [{file,"supervisor.erl"},{line,414}]},
                          {supervisor,do_start_child,2,
                           [{file,"supervisor.erl"},{line,400}]},
                          {supervisor,'-start_children/2-fun-0-',3,
                           [{file,"supervisor.erl"},{line,384}]},
                          {supervisor,children_map,4,
                           [{file,"supervisor.erl"},{line,1250}]},
                          {supervisor,init_children,2,
                           [{file,"supervisor.erl"},{line,350}]},
                          {gen_server,init_it,2,
                           [{file,"gen_server.erl"},{line,848}]},
                          {gen_server,init_it,6,
                           [{file,"gen_server.erl"},{line,811}]}]}}}},
                     {elixir,start,[normal,[]]}}
      in function  application_master:init/4 (application_master.erl, line 142)
    ancestors: [<0.79.0>]
    message_queue_len: 1
    messages: [{'EXIT',<0.81.0>,normal}]
    links: [<0.79.0>,<0.44.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 1598
    stack_size: 28
    reductions: 245
  neighbours:

> =INFO REPORT==== 18-Mar-2024::19:54:46.677289 ===
    application: elixir
    exited: {{shutdown,
                 {failed_to_start_child,elixir_code_server,
                     {'EXIT',
                         {undef,
                             [{elixir_code_server,start_link,[],[]},
                              {supervisor,do_start_child_i,3,
                                  [{file,"supervisor.erl"},{line,414}]},
                              {supervisor,do_start_child,2,
                                  [{file,"supervisor.erl"},{line,400}]},
                              {supervisor,'-start_children/2-fun-0-',3,
                                  [{file,"supervisor.erl"},{line,384}]},
                              {supervisor,children_map,4,
                                  [{file,"supervisor.erl"},{line,1250}]},
                              {supervisor,init_children,2,
                                  [{file,"supervisor.erl"},{line,350}]},
                              {gen_server,init_it,2,
                                  [{file,"gen_server.erl"},{line,848}]},
                              {gen_server,init_it,6,
                                  [{file,"gen_server.erl"},{line,811}]}]}}}},
             {elixir,start,[normal,[]]}}
    type: temporary

> =INFO REPORT==== 18-Mar-2024::19:54:46.677488 ===
    application: compiler
    exited: stopped
    type: temporary
{"init terminating in do_boot",{{badmatch,{error,{elixir,{{shutdown,{failed_to_start_child,elixir_code_server,{'EXIT',{undef,[{elixir_code_server,start_link,[],[]},{supervisor,do_start_child_i,3,[{file,"supervisor.erl"},{line,414}]},{supervisor,do_start_child,2,[{file,"supervisor.erl"},{line,400}]},{supervisor,'-start_children/2-fun-0-',3,[{file,"supervisor.erl"},{line,384}]},{supervisor,children_map,4,[{file,"supervisor.erl"},{line,1250}]},{supervisor,init_children,2,[{file,"supervisor.erl"},{line,350}]},{gen_server,init_it,2,[{file,"gen_server.erl"},{line,848}]},{gen_server,init_it,6,[{file,"gen_server.erl"},{line,811}]}]}}}},{elixir,start,[normal,[]]}}}}},[{elixir,start_cli,0,[{file,"src/elixir.erl"},{line,198}]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}
init terminating in do_boot ({{badmatch,{error,{elixir,{_}}}},[{elixir,start_cli,0,[{_},{_}]},{init,start_em,1,[]},{init,do_boot,3,[]}]})
Crash dump is being written to: erl_crash.dump...done

な、ながい...
ググったらForumにこんなお話が

> Elixir is precompiled for OTP 22 which is not fully compatible with OTP 25. You need to either use OTP 24 or compile Elixir from source.

https://elixirforum.com/t/error-beam-beam-load-c-86-error-loading-module-elixir-code-formatter/48003

原因はOTP26をwgetしていたことでした。
一旦
sudo apt remove elixir -y
を行い、
sudo apt update -y
も行った後にOTPを25に変更しコマンドを進めていくと...
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/330568/f0a389b7-93d3-b1dc-e8e4-11d3b7b38a2c.png)

できました！

あとがき
参考記事は問題なく丁寧に記載されていたのですが、Elixirのバージョンの変化が速かったのか、OTP26という存在がネックになっていました。
なぜうまくいかないのかと悩みましたがこれで解決できて何よりです。