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



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:


#!/usr/bin/env elixir

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

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 and extracting the vsn? On Alpine:

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

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

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

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

Oh nice, I didn’t know there’s an 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…

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.