E1.獲取Elixir/Erlang版本信息
E1.獲取Elixir/Erlang版本信息
獲取Elixir版本
直接在shel中打開iex
(interactive shell),就可以查到具體的版本信息:
iex
Erlang/OTP 22 [erts-10.6] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]
Interactive Elixir (1.9.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
使用符合GUN選項標準--version
或-v
,比如在寫Shell腳本時可以用來判斷版本。
iex --version
Erlang/OTP 22 [erts-10.6] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]
IEx 1.9.0 (compiled with Erlang/OTP 22)
iex -v
Erlang/OTP 22 [erts-10.6] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [dtrace]
IEx 1.9.0 (compiled with Erlang/OTP 22)
在代碼中獲取版本信息:System.version/0
iex(1)> System.version
"1.9.0"
獲取Erlang版本
Erlang無法使用erl --version
命令,只能通過命令行選項eval與noshell參數求值來實現。
erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell
eval
:對Erlang表達式求值。noshell
: 不啟動shell,就像上面的elixir –version一樣。halt()
退出當前運行時
由於:erlang.system_info(:opt_release)
只能拿到一個大版本號:比如22:
iex(1)> :erlang.system_info(:otp_release)
'22'
如果想要更詳細的版本信息可以使用:
erl -noshell -eval \
> '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().'
22.2
上面的代碼來源於Erlang官方文檔。
多個表達式寫成一行使用逗號隔開,顯得不那麼容易理解,還可以把多個表達式分開寫:
erl -noshell -eval \
'{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version).'\
-eval 'halt().'
22.2
或用-s
參數:
erl -noshell -eval \
> '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version).'\
> -s erlang halt
22.2
PS:上面的OTP_VERSION
文件是從R17後才有的。
從R17開始,OTP的大版本代表的是一組特定版本的應用(Applications),這一組合通過了愛立信官方OTP團隊的測試,但是個人也可以不升級大版本,只升級其中的某個特定應用的版本,這樣的組合的兼容性沒有經過官方驗證/測試,需要自己充分測試,所以沒有經過充分的測試,別只單獨升級個別應用,最佳實踐是保持和官方大版本一致的應用版本。
It is therefore always preferred to use OTP applications from one single OTP version.
想要得到那些應用在本版本做了變更,可以查看查看otp_versions.table,它羅列了每個版本具體的改動情況,每一行代表一個版本,比如:
OTP-22.1.1 : compiler-7.4.6 erts-10.5.1 snmp-5.4.1 # asn1-5.0.9 common_test-1.18 crypto-4.6 debugger-4.2.7...
OTP-22.1.1
: OTP版本。compiler-7.4.6 erts-10.5.1 snmp-5.4.1:
發生了變更的應用。#
後面的應用為未發生變更。