132

Many programs return their version number with a command like:

$ program --version
program (platform info) v1.2.3

This is useful for scripting the installation or maintenance of the program, and some other controlled automation magic from System Admins and friends.

Problem

How to easily get the version number for Erlang (OTP)?

On the net

Here are some unsatisfactory solutions (from the trapexit forum and other tutorials/Erlang documentation):

Emulator

$ erl
1> erlang:system_info(otp_release).
"R13B03"

Hard to script. I have not found a way to have erl execute a single command from a shell prompt.

Release file

$ cat /usr/lib/erlang/releases/RELEASES
[{release,"OTP  APN 181 01","R13B03","5.7.4",
      [{kernel,"2.13.4","/usr/lib/erlang/lib/kernel-2.13.4"},
       {stdlib,"1.16.4","/usr/lib/erlang/lib/stdlib-1.16.4"},
       {sasl,"2.1.8","/usr/lib/erlang/lib/sasl-2.1.8"}],
      permanent}].

Parsing paradise (with shell).

An alternative could also be checking the install path, but that is not portable (my install path does not include the version, for one).

Personal context: I am writing a script to install the same version of RabbitMQ with plugins on several machines. Some plugins have minimal requirements on the OTP version, and it is how this question started.

Josiah Yoder
  • 3,321
  • 4
  • 40
  • 58
Eric Platon
  • 9,819
  • 6
  • 41
  • 48

12 Answers12

175
 erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().'  -noshell
Odobenus Rosmarus
  • 5,870
  • 2
  • 18
  • 21
  • sorry didn't see more comprehensive previous answer when I post it – Odobenus Rosmarus Mar 05 '12 at 03:51
  • 3
    This prints `(no error logger present) error: "Error in process <0.0.0>` on Windows 7 for me. -1 – Jonas Jan 16 '14 at 11:42
  • @Jonas try werl instead of erl – tmj Jun 05 '15 at 22:09
  • For precise version run: `erl -eval 'erlang:display(erlang:system_info(version)), halt().' -noshell` – andPat Jul 28 '15 at 15:57
  • 1
    @andPat, your suggestion returns the version of the erlang _shell_ for me (e.g. `7.0.2`), not erlang itself (`18`, in my case). – gdw2 Jul 29 '15 at 21:42
  • 7
    From the docs for erlang:system_info: _As from OTP 17, the OTP release number corresponds to the major OTP version number. No erlang:system_info() argument gives the exact OTP version._ See my answer below for an even uglier command that also prints minor version on my development machine. – Jay Dec 17 '15 at 03:40
  • 3
    On Windows 7, I had to replace the single quotes with double quotes. `erl -eval "erlang:display(erlang:system_info(otp_release)), halt()." -noshell` – yohosuff Mar 22 '18 at 15:38
118

The other answers only display major version as of OTP 17 (from docs for erlang:system_info). This works to display major and minor version on my development machine:

erl -eval '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().' -noshell

This reads from the appropriate file, as described in the docs.

Sheharyar
  • 73,588
  • 21
  • 168
  • 215
Jay
  • 3,857
  • 2
  • 23
  • 25
  • 4
    Thanks, this is useful! Also, you can get rid of the quotes and `\n` and also make the code shorter with just one change: `erl -eval '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().' -noshell`. – Dogbert Oct 09 '16 at 10:54
  • 1
    On Windows 7, I had to swap single quotes with double quotes (and vice versa). `erl -eval "{ok, Version} = file:read_file(filename:join([code:root_dir(), 'releases', erlang:system_info(otp_release), 'OTP_VERSION'])), io:fwrite(Version), halt()." -noshell` – yohosuff Mar 22 '18 at 15:40
49

(I'm adding this answer here since I've searched for this at least 3 times in the past three months)

Starting from version 17.0 releases have a new format in their version number (17.0, 17.1, ...) but erlang:system_info(otp_release). only returns the major version number.

In order to get the full version number it is necessary to check the contents of the OTP_RELEASE file under the already mentioned releases folder.

$ which erl
/usr/bin/erl
$ cd /usr/bin
$ ls -l erl
../lib/erlang/bin/erl
$ cd ../lib/erlang/
$ cat releases/17/OTP_RELEASE
17.3

EDIT

# Some versions seem to have OTP_VERSION instead of OTP_RELEASE
$ cat releases/17/OTP_VERSION
17.4
juan.facorro
  • 9,791
  • 2
  • 33
  • 41
  • I don't find that file by your description, `find / -name "OTP_RELEASE"` doesn't see it either, but I have OTP 17.x installed. How am I able to know what "x" is? – NobbZ Apr 21 '15 at 14:30
  • 2
    @NobbZ I updated the answer with additional info, I just checked and in the current Erlang/OTP version I have installed (17.4) the file is actually called `OTP_VERSION`. – juan.facorro Apr 21 '15 at 18:42
  • 2
    with one line `cat $(dirname $(dirname \`which erl\`)/$(readlink \`which erl\`))/../releases/*/OTP_*` – Lol4t0 Jun 28 '15 at 11:54
19

To retrieve EShell (Erlang Shell) version, you may use:

erlang:system_info(version).

and to retrieve Erlang OTP (Open Telecom Platform) version:

erlang:system_info(otp_release).


enter image description here

vulcan raven
  • 32,612
  • 11
  • 57
  • 93
Miloud Eloumri
  • 779
  • 1
  • 8
  • 14
14

init docs, linked by 'man erl'.

-eval Expr

Scans, parses and evaluates an arbitrary expression Expr during system initialization. If any of these steps fail (syntax error, parse error or exception during evaluation), Erlang stops with an error message. Here is an example that seeds the random number generator:

% erl -eval '{X,Y,Z} = now(), random:seed(X,Y,Z).'

This example uses Erlang as a hexadecimal calculator:

% erl -noshell -eval 'R = 16#1F+16#A0, io:format("~.16B~n", [R])'  -s erlang halt
BF

If multiple -eval expressions are specified, they are evaluated sequentially in the order specified. -eval expressions are evaluated sequentially with -s and -run function calls (this also in the order specified). As with -s and -run, an evaluation that does not terminate, blocks the system initialization process.

Thus,

$ erl -noshell -eval 'io:fwrite("~s\n", [erlang:system_info(otp_release)]).' -s erlang halt
Community
  • 1
  • 1
Julian Fondren
  • 5,459
  • 17
  • 29
8

Find in /usr/lib/erlang/releases/18/OTP_VERSION

Eduardo Cuomo
  • 17,828
  • 6
  • 117
  • 94
Sener DEMIRAL
  • 89
  • 1
  • 2
4

erl +V or you can use erl -version

result : Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 5.8.5

shrikant
  • 65
  • 1
  • 1
  • 5
    This returns the `erl` emulator version, not the Erlang release version number (e.g. "R15B03"). All that could be so easy ;-) – Eric Platon Jun 18 '13 at 01:28
3

Based on Jay's answer above, I wrote the following shell function that I can use:

erlang () {
    if [[ $@ == "-v" ]]; then
        command erl -eval '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().' -noshell
    else
        command erl
    fi
}

I often forget that the command is erl rather than erlang, so this lets my forgetful brain just use erlang as if it were erl, and erlang -v like I would expect from something like elixir.

Josh Smith
  • 14,674
  • 18
  • 72
  • 118
2

Finds the erl in your PATH and reads the RELEASES file to extract the erlang release number.

awk -F, 'NR==1 {gsub(/"/,"",$3);print $3}' "$(dirname $(readlink -f $(which erl)))/../releases/RELEASES"
juan.facorro
  • 9,791
  • 2
  • 33
  • 41
taylorcc
  • 21
  • 1
2

Open terminal and enter command erl

You will get the following output:

Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false] Eshell V5.10.4 (abort with ^G)

Erlang R16B03 (erts-5.10.4) [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false] - This is the language version

Eshell V5.10.4 (abort with ^G) - This is the shell version

akhileshnair
  • 1,437
  • 1
  • 12
  • 18
-4

I ran the updates for the systems and works

sudo apt-get update
sudo apt-get upgrade
Syscall
  • 19,327
  • 10
  • 37
  • 52
direyes
  • 53
  • 4
-9

A simple command you can use:

erl --version
Jeremie Ges
  • 2,747
  • 3
  • 22
  • 37