Elixir development in Windows 10

I’m a beginner on Elixir ecosystem, and lately I was struck with the fact that developing elixir on Windows 10 may have some problems.

My case was that I was happily developing a phoenix API until I needed the lib bcrypt_elixir and so my world crashed. It was giving some errors saying it couldn’t find some things I didn’t know it depended on (nmake), so to make this work I’d have to install Microsoft C++ Build Tools ( :face_vomiting:) and do some other things. Later someone told me that I could face more problems later on if I’m to develop with windows.

The workaround would be to work with WSL2, but I don’t have many computational resources to use it without taking many minutes to start a phoenix server, for example.

Changing the OS is not an option, for now.

So, what I want to know is if someone does work with windows 10 for elixir/phoenix development and what are they doing to bypass these problems?

Thanks for your time !

Hi @wallysoncarvalho,

There are a few threads you can search on here for help with building bcrypt on Windows. For example Error compiling :bcrypt_elixir and :argon_elixir

Also, the wiki page here: https://github.com/riverrun/comeonin/wiki/Requirements describes the pre-requisites for getting comeonin and bcrypt to build.

I’m developing Elixir on Win 10 fine without WSL. That’s the least of my worries with Win 10 to be honest. I also use Kubuntu & Mac regularly and Win 10 is my least favourite, but works fine.

2 Likes

Welcome to the forum!

Setting up an Elixir / Phoenix development environment on Windows 10 can involve a certain degree of frustration, mainly in relation to C++ / Visual Studio. In my experience, however, this was more like a teething problem, not the sort of issue that should make you consider switching OS. Eventually, things seem to work reasonably well.

1 Like

You can try to make it work on windows by following the instructions on the bcrypt site and install that bloated Microsoft dependency, or MSYS or cygwin, or WSL.

You can also just drop bcrypt and use pbkdf2_elixir, which is a password hashing algorithm implemented in pure elixir.

When dealing with NIFs or FFI (native code in general) in Windows, about any language will give you trouble.

4 Likes

I am a win10 user myself. As others already stated: The C bindings of an application designed for unix alike systems, is still a horror to work with in pure windows environments. So WSL2 would be my first choice here. Even just a single docker elixir container running on windows hyperv with your sourcode folder mounted, would be a better choice than running elixir natively on win10.

If this still is too much load for the machine you are working with: Here are some explicitly secondary(!) choice workarounds. If I would be in your shoes, with not much of additional resources, I would consider:

a) to start working completely on a remote workspace or (v)server. For the network/backend development case, it is not that different to work with WSL2, since you just utilize the unix alike envorinment and the network interfaces. VPN might be required. Really depends on the remote environment. There are both, flat fee or charge by the minute options.If you are student or startup there are often campaigns with lots of free credits for AWS, GCP and alike.

b) to go for an experiment and use a remote machine to run a BEAM instance with your “c or load critical” code as a service. I would try to connect my local BEAM with the remote BEAM. So your local instance can send/receive messages to/from the remote instance with the pure erlang vm capabilities. No JSON, no REST or alike. By this approach you just outsourced what doesn’t perform well locally to a remote machine.

For both cases it would apply, that you would have to work in a remote environment though. Or you can find an editor that does SSH very well. Probably a bit hacky and shaky, but considering your situation, it is still great opportunity to learn a lot about networking, different environments and OTP.

Hope that helps!

1 Like

Hi @wallysoncarvalho, welcome to the forum!

I spent the last year working with Elixir/ Phoenix using Windows 10 until I had a problem with some NIFs that needed to be compiled and I couldn’t find a sane way to make it work with the tools available to me (not that it’s impossible, but I just didn’t want the trouble).

I installed PopOS and used it for three weeks, missed my old workflow, and switched back to Windows 10 with WSL2 enabled (I’m happy ever since).
Right now, Win10 is the perfect OS for development (IMHO), just because I have all the tooling I need - including a Linux environment for development. Also, I’m using Windows 10 Single Language with WSL2 and have almost no performance issues¹, so I’m curious why you said you don’t have “many computational resources”.

¹ Just to be clear: WSL2 is far from perfect, but Microsoft is doing a lot to improve it and things only will get better going forward. For example, there’s no support for systemd right now, so I have to manually start some services when I open the WSL session for the first time (eg postgres). The other thing that I miss is :observer.start() (right now, you can get it to work using an unofficial XServer for WSL, but official support is on its way)

1 Like

Yea ever since WSL2 I have been leveraging it vscode + docker to for all development.
Been quite happy with it.

Overhead of WSL2 is tiny, more efficient than running a VM I would think.

So from what i understand, in the solution on the wiki page, for every time i open a terminal do run mix commands i’ll have to run vsdevcmd.bat ? Is that right ?

I loved using it, but for my current machine it cost a lot of resources.

I install visual studio and c++ build tools to compile NIF stuff, you only need to do this once when compiling the dependencies. It’s not that bad, after installing the build tools you get “x64 Native Tools Command Prompt for…”, this gives you a shell with the right compiler env and it will just work.

I run my elixir project from a Git Bash, it’s MINGW32. Cmder also works.

3 Likes

Well, but every time we need to run a command that needs NIF we need to do that “dance”, right?
I installed Microsoft Visual Studio 14.0 Build Tools (jesus christ, that’s was almost 1GB :sob:) with choco and it compiled, but Visual Studio Code was still showing errors regarding not finding nmake; my temporary solution was to change to pbkdf2_elixir lib.

Anyway, there’s a lot of workaround for this, but I’m still not happy about it.

All the answers were of great help, thanks to everyone that contributed.

That’s why VS gives you scripts that populate the environment before working with it. Check what @xlphs said:

I always opted for another approach though: I inspected the .bat files that VS provides and simply integrated their environment exports in my global env vars and called it a day. But many people prefer to just call the scripts first and then do their work.

As an example, to open a ‘working command prompt’ I run:

cmd.exe /k chcp 65001 & echo; & "C:\Program Files...\Visual Studio\Common7\Tools\VsDevCmd.bat" -arch=x64 & D: & cd "D:\pathToMyProject"