Is it possible to enable a command history feature for the iex console?

I mean to be able to go back to previously used commands using the up arrow key.

3 Likes

This is enabled by default for all versions of Erlang, but only ever affects the current session.

From Erlang OTP 20 on, you can enable a history that spans sessions:

Be aware though that on windows you might need to use werl/iex --werl.

4 Likes

I am running latest OTP and have just enabled it by:

export ERL_AFLAGS="-kernel shell_history enabled"

4 Likes

Hi all,

First off, not sure if I’m breaking protocol by replying to an older thread - apologies if I am.

I’ve tried this a few times in my .bashrc .profile, and .bash_profile, to no avail … if anyone has any other ideas that would be massively appreciated please.

Thanks,

Viv

Are you using bash?

Have you restarted your shell after adding the export?

I am using bash. Do I need to fully close out my terminal, or can I simply source my updated profile file - which is what I did?

Sourcing should be enough.

What version of erlang are you on?

Erlang:
Erlang/OTP 23 [erts-11.0.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]
Eshell V11.0.3

Elixir:
Erlang/OTP 23 [erts-11.0.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [hipe]
Interactive Elixir (1.10.4)

Thanks.

When you have that export enabled and you start erl or iex, issue a command, exit it, then start again and push ?

If you do System.get_env("ERL_AFLAGS") in iex, what does it return?

I get the following:

iex(1)> System.get_env("ERL_AFLAGS")
"-kernel shell_history enabled"

Hmmm … I know this is going to sound silly, but let me completely restart my gnome session and reboot and see what happens … I’ve seen some quirks previously where settings changes didn’t seem to apply until I rebooted …

All working now, sorry for the noise.

Thanks for all your help @NobbZ.

1 Like

I had the same issue. I tried everything from setting the ENV to restarting the machine but in the end, it was a mismatched OTP version. I used 1.14.3-otp-25 as my Elixir version but the Erlang version was set to 26.1.2. After changing the Elixir version to 1.15.7-otp-26 it worked as expected. Leaving this reply as a future reference for myself and others who are in a similar situation and trying to fix the same problem.

2 Likes

This was my issue as well.

Thanks for posting this :fist_right: :fist_left:

2 Likes