Skip to content
Rui Lopes edited this page Jun 16, 2024 · 12 revisions

All things related to Elixir on Windows.

Note: There's an alternative approach here that will allow you to skip using cygwin/msys, etc. in favor of executing Linux binaries directly - no VM required at all - on your Windows 10 machine. Skip to the section on WSL for more.

Building

The recommended way to build Elixir on Windows is with tools provided by MinGW and MSYS. Although MinGW is used for building Elixir, it is not necessary for running Elixir. In addition to MinGW, you'll need Git and Erlang on your system.

Installing MinGW

First, if you don't already have the MinGW Installation Manager on your system, download mingw-get-setup.exe here and run it. This will provide a package manager interface from which you can install the necessary MinGW/MSYS components. In the interface, mark the following packages for installation:

  • msys-bash (bin)
  • msys-grep (bin)
  • msys-make (bin)

Then, in the Installation menu, select Apply Changes.

Finally, you'll need to add the directory containing these packages to your system's Path environment variable. By default the path is C:\MinGW\msys\1.0\bin. To do this:

  1. Press Win + R to open the Run dialog
  2. Type "SystemPropertiesAdvanced.exe" and press Enter.
  3. Click "Environment Variables..."
  4. Under "System variables", select "Path" and then click "Edit..."
  5. Append the directory to the variable value, using a semicolon to separate the directory form the other entries.
  6. Click "OK" in each of the open windows.

Installing Git

If you don't already have Git installed, you can download it here and install it. A directory containing git.exe needs to be in your Path environment variable (see above for how to add it). By default, the installation puts git.exe in C:\Program Files (x86)\Git\cmd.

Installing Erlang

If you don't already have Erlang installed, you can download it here and install it. A directory containing erl.exe needs to be in your Path environment variable (see above for how to add it). By default, the installation puts erl.exe in C:\Program Files\erlX.Y\bin or C:\Program Files (x86)\erlX.Y\bin.

Compiling Elixir

Once you have the necessary tools, open up a Command Prompt in your favorite directory and follow these steps to compile Elixir:

  1. Clone the Elixir repo to your system using git clone https://github.com/elixir-lang/elixir.git
  2. Change into the repo directory using cd elixir
  3. Run make.

It's that simple!

Gotchas

Here are some snags you might run into while working with Elixir on Windows.

  • Symlinks creation requires Administrator privileges by default; File.ln_s/2 will return {:error, :eperm} if the associated erl.exe or werl.exe process is not running as an Administrator. You can allow creation of symlinks by normal users by following the steps on https://superuser.com/a/125981
  • Paths with backslashes aren't supported because the backslash is used for escape characters. For example, C:\Users\Chris doesn't work, but C:/Users/Chris or C:\\Users\\Chris do.
  • There is problem with variable MAKE in Makefile - it causes this error during compilation:
    PS C:\projects\elixir> make clean test
    #cd lib/elixir && "/c/projects/elixir/rebar" clean
    #==> elixir (clean)
    #rm -rf ebin
    #rm -rf lib/*/ebin
    #/bin/sh: /c/projects/elixir/C:/MinGW/msys/1.0/bin/make.exe: No such file or directory
    #make.exe": *** [clean] Error 127
    
    The easiest workaround is to add line MAKE = make to the beginning of Makefile

WSL

...stands for Windows Subsystem for Linux and is an implementation of Linux kernel syscalls directly in the Windows 10 kernel itself. This means fully compiled, native 64-bit Linux binaries will run directly on Windows without any VM!

As of this writing it's still considered "beta" by Microsoft, but don't let that scare you off: the vast majority of competent users have reported great success in using this feature. Early releases had not yet solved problems like binding to, say, localhost:8080 from a process launched under WSL/bash and being available from the browser running on the regular Windows side of things, but that seems to have been worked out for a while now. Some users have even been able to run X11 applications natively on Windows 10! (And some of them have been doing it since WSL's very first early releases!)

Quick walk-through:

  1. Make sure you're logged in as a local user with full admin privileges.
  2. Hit start, find the "Settings" app (not Control Panel, literally it's a Universal Windows Platform (UWP) app called "Settings"; yeah, I agree it's somewhat ambiguous but meh, carry on...)
  3. Click the big "Update and Security" grid square
  4. Now on the left side toward the bottom of this text list you should see an entry entitled "For Developers". Hit it.
  5. Click the "Developer Mode" radio button. Close the window (there's no "Apply/OK" button in this app)
  6. Back to the desktop -> click Start and find "Control Panel" then open it.
  7. Control Panel -> Add/Remove Programs -> Left side panel, look for "Windows Features" and click it
  8. Scroll through the list and find "Windows Subsystem for Linux" and check it, hit OK
  9. Let it install and reboot. You know how Windows just looooves to be rebooted :)
  10. After it's back up, log in to that same admin-enabled account again
  11. Hit the WIN+X key combo (yes, X, that's not a typo) and find the option to run Windows PowerShell as an Administrator
  12. Click the "yeah yeah nobody cares" button (User Access Control prompt) and then when your Powershell prompt is up, run this:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Let it finish its thing, then run this (also as an admin user in PowerShell - same shell session should be fine)

bash

Now you'll be prompted to agree to some crazy legal terms so just accept it blindly like everybody does and it'll perform the full installation of WSL. When that's done you'll be asked to create a user and a password. These are totally SEPARATE from your normal Windows user account/password. As long as your dev box is secure (say, a full desktop in your home which just happens to be an underground bunker or something), you can just make this "dev/dev" if you want.

But don't forget that password. You'll need it to install packages because you'll still have to sudo apt ... to administer the Linux side of things.

Yeah so you done that? Great. Now if it says reboot, then reboot. However don't be surprised if you don't have to.

When that's done, just launch a regular terminal process (WIN+R, then type cmd and hit enter, or WIN+X and click the non-admin PowerShell option), then type bash and hit enter. In fact, you might...haha, "bash" that enter key, if you know what I mean. 🙄 😆

Congratulations, you're now running Linux NATIVELY on the Windows 10 kernel!

For kicks, try installing neofetch!

$ sudo add-apt-repository ppa:dawidd0811/neofetch && sudo apt update && sudo apt install neofetch -y
$ neofetch

You should see output similar to what the author of neofetch shows on the project's GitHub readme.

Links + Info

Clone this wiki locally