Getting started with Erlang and Cowboy on Windows (erlang.mk edition)

This is the first in a series of posts on getting up and running writing microservices using Erlang and Cowboy, for those of us who chose to (or are required to) develop in a Windows environment.

Of course, one could get snarky and say “Install VirtualBox – done.” But let’s be a little more polite to the Windows users here. Windows is a supported platform for Erlang, so I want to provide assistance for those who choose, or need to use, Erlang in this way.

Without further ado…

Cowboy (user guide, manual), for those who don’t know, is a library for writing web services in Erlang. It’s written by the folks at Nine Nines, primarily by Loïc Hoguin if I’m not mistaken. Using Cowboy, it is relatively easy to get up and running writing an Erlang web service which leverages Erlang’s OTP framework.

Cowboy works great on Linux. I do not see explicit support for Windows, and most resources I have Googled have been rather hit-or-miss as to how to get started on Windows. But, it does indeed work on Windows – it’s just perhaps a little unclear to the novice how to make this work.

Here is the procedure I used:

  1. Download and install Erlang.
  2. Install Msys2 from https://msys2.github.io/. Follow all the steps on the msys2 home page before continuing further.
  3. Open the Msys2 Shell.
  4. Install packages needed for running erlang.mk Makefiles: pacman -S git make
  5. Install other packages needed for walking through the tutorial docs: pacman -S wget
  6. Find where erl.exe is located via the Msys2 shell. For example, if erl.exe is located in the directory “C:\Program Files\erl6.2\bin”, you’ll find it at “/c/Program Files/erl6.2/bin”. (Test this via the command: ls -l <path/to/erl.exe>)
  7. Add the directory from the previous step to your environment PATH variable, both for the current and future sessions. You can do this via the following shell snippet; just be sure to tweak the erl_dir variable at the start before running it.
    # Update this to reflect where erl.exe is found on your system.
    erl_dir="/c/Program Files/erl6.2/bin"
    
    # This will add Erlang to your path for the current session...
    export PATH="$PATH:$erl_dir"
    
    # ...And this will do the same for future sessions
    echo >> ~/.bashrc
    echo '# Add Erlang to PATH' >> ~/.bashrc
    echo 'export PATH="$PATH:'$erl_dir'"' >> ~/.bashrc
    
  8. Follow the instructions on the “Getting started” page, with the following caveats:
    • Running the server via Msys2 is done via the command ./_rel/hello_erlang_release/bin/hello_erlang_release.cmd console. (Note the added “.cmd”.)
    • Tutorial errata: It seems that current versions of erlang.mk don’t generate the src/hello_erlang.app.src file expected by the tutorial. I’m not sure of the overall impact, but it appears safe to ignore this for the purpose of cowboy. I could run through the rest of the tutorial without problems.
  9. With the above, you should be able to successfully complete the Cowboy “Getting Started” tutorial on Windows.

    My next post will be on the same topic, but will cover using rebar3 instead of erlang.mk. Stay tuned.

Leave a Reply

Your email address will not be published. Required fields are marked *