What I’m used to do is to hit Ctrl-Ctwice. It has the same effect as the abort command.

The Break command can be triggered from any running Elixir code and not only iex. But I always feel this is somewhat dirty. That by dropping into the Break command and exiting from there, I’m leaving my session opened. I know this is not the case but I went to find other ways to exit the shell.

Ctrl-G

You may have heard about Ctrl-G. If you type it in your IEx session, you’ll see:

iex(1)>
User switch command

This drops you into the User switch command, or Job Control Mode (JCL), if you read about it in the Erlang documentation.

In this mode, you can create new shells (local and remote ones), list and terminate them:

If you use q in this mode, you’ll halt your Erlang system, similar to aborting through the Break command. However Job Control Mode only works within IEx and therefore it is somewhat more restricted compared to Ctrl+C.

Ctrl-\

You may have tried Ctrl-D, a.k.a the End-of-Transmission character. Turns out Erlang and Elixir don’t understand it the way we are used from other REPLs.

What I didn’t know is that you can exit the shell by sending Ctrl-\. The shell will exit immediately. As far as I know, it has the same effect as aborting the shell in the Break command, it doesn’t affect remote nodes and it also works outside of iex (for example, you can use to terminate your tests). I only found out about it in this brief passage in the Erlang FAQ.

Now that’s a quick and proper exit. My search is complete. Now I just need to retrain my muscle memory.

6 responses to “How to quit the Elixir shell (IEx)?”

For Windows use iex –werl as then you get working tab completion and some other features in a full Erlang window. To quit that use Control + G then ‘q’uit. I would say don’t bother using iex in a normal command window as it’s too frustrating to be useful.

You can use `System.halt` which uses Elixir’s module. The trouble with such command though is that it will shut down the node you are currently connected to on remote cases instead of just exiting the shell.