Retrieving Elixir version in command line without `elixir --version`

Hi folks,

Does anyone know a good way to retrieve the current elixir version on your system without running elixir --version?

I’m looking into modifying starship’s elixir version retrieval to stop doing that because running elixir --version will result in booting the Erlang VM and is extremely slow.

I know > v1.13 has --short-version that’s a faster alternative, but are there other ways of getting a similar result while also can be backwards compatible?

PR: Add `elixir --short-version` for better performance by darwin67 · Pull Request #5114 · starship/starship · GitHub

Issues:

4 Likes

Does it necessarily have to be with the elixir command? If user already elixir installed so System.version returns the same result as elixir --short-version, so you can have:

#version.exs

#!/usr/bin/env elixir
System.version

ignre this, the script will boot the vm anyway

I’m just bashing the keyboard, but there seems to be a VERSION file you can read, if you can find the installation. Confirmed it’s present on 1.11 and also in the precompiled packages.

I’m using ASDF, so this works for me:

$ cat $(asdf where elixir)/VERSION
1.11.4
2 Likes

Elixir installed via apt does not comes with VERSION file, the output for dpkg -S elixir and dpkg -L elixir I could not found this file.

How about finding elixir.app and extracting the vsn? On Alpine:

$ cat /usr/local/lib/elixir/lib/elixir/ebin/elixir.app | grep vsn | cut -d '"' -f2
1.14.4

Edit: playing around, there’s probably a better way…

$ cat $(realpath $(dirname $(readlink -f $(which elixir)))/../lib/elixir/ebin/elixir.app) | grep
vsn | cut -d '"' -f2
1.14.4
3 Likes

Oh nice, I did not knows that .app contains the version!

Oh nice, I didn’t know there’s an elixir.app either!
This does looks like it can get pretty complicated pretty quickly due to having to check multiple files. :thinking:

@josevalim could you provide some hints if there’s a better way of doing this? :slight_smile:

It might be easier to just wait till < 1.13 support are completely deprecated…
https://hexdocs.pm/elixir/1.14.4/compatibility-and-deprecations.html

Check elixir --short-version and if it doesn’t succeed, use elixir --version? So those who update have the fast path, others can update if they need it.

2 Likes