Skip to content

Instantly share code, notes, and snippets.

@bmitc
Last active January 6, 2023 07:14
Show Gist options
  • Save bmitc/b24317cf6c2f37ebd280c5aac62d9dce to your computer and use it in GitHub Desktop.
Save bmitc/b24317cf6c2f37ebd280c5aac62d9dce to your computer and use it in GitHub Desktop.
Configure Elixir's IEx and Mix on Windows

Introduction

Elixir's IEx and Mix tooling, on Windows, comes with some batch scripts (.bat) and PowerShell scripts (.ps1) that handle these tooling applications. For example, you can run

PS > (Get-Command mix.ps1).Path
C:\Program Files (x86)\Elixir\bin\mix.ps1

to see where these scripts are located, if they are in your path already. The Elixir Winows installer does put these in your path if you select it (I think there's a selection at least, from memory).

So out of the gate, you need to run iex.bat and mix.bat to run these commands for Elixir, which can be problematic. See the steps below to get rid of this requirement.

The following assumes the editor is Visual Studio Code and that code is available in the user's path.

IEx

By default, PowerShell contains an alias iex for Invoke-Expression. To see this:

PS > $alias:iex
Invoke-Expression

Thus, to make iex for Elixir work, even with it in the path, this alias needs to be removed.

  1. Enable script execution: Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    • Warning: Please read the PowerShell documentation to understand this command! I'm not responsible for unwanted scripts running on your computer.
  2. Open the PowerShell profile by running code $PROFILE. The profile may not exist. If not, see the PowerShell documentation on profiles.
  3. Add
    if (Test-Path alias:iex) {
        Remove-Item alias:iex -Force
    }
    to your profile file. This tests if the $alias:iex exists or not, and if so, forces its removal. Note, there is a commandlet called Remove-Alias, but this requires PowerShell 6.
  4. You can try running & $profile after saving the profile file, but this didn't work for me. Open a new PowerShell, and you should be able to run iex now and get Elixir's IEx.

Mix

Being able to run just mix instead of having to use mix.bat is enabled by step (1) in the above IEx section, since this enabled PowerShell scripts to run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment