Getting Elixir/Phoenix running under Windows
This is a basic set of notes on getting a Windows 10 machine set up for development with Elixir and Phoenix.
Getting started
This is largely based on the Phoenix installation details, expanded with extra info for Node and Postgres.
Install the ecosystem
All the installations should be attempted without using Administrator mode first both for security and isolation reasons.
- Install Erlang (v22+) and Elixir (Windows installer available here)
- Test the installation with
erl -v
andelixir -v
- Test the installation with
- Install hex (package manager) using
mix local.hex
- Test the installation with
mix hex.info
- Test the installation with
- Install Phoenix framework using
mix archive.install hex phx_new 1.5.12
- The version number is optional; drop it to default to the latest
- Test the installation with
mix phx.new -v
Optionally install client-side build ecosystem
Note: Phoenix 1.6 or later removes the need for Node and npm (unless you want to continue using webpack). These instructions retain Node configuration as most beginners use books like Programming Phoenix 1.4, or tutorials, or have existing codebases to work on, so they are expected to be using earlier versions.
If you create Phoenix apps with the --no-webpack
option or are using v1.6+ then Node isn't required. Otherwise you should use nvm to install Node version 5 or later. Whilst you can install Node directly, using nvm allows you to maintain multiple isolated Node versions and easily/safely switch between them.
- Install nvm (Windows installer available from here)
- Test the installation with
nvm -v
- Test the installation with
- Optionally set the nvm version storage folder (eg if your username path has spaces)
- Run
nvm root
to get the location of the current nvm folder (probably anAppData\Roaming
path) - Make and select a new root using
mkdir c:\nvm-versions && nvm root c:\nvm-versions
- In Explorer copy all the files (apart from any
unins*
ones) from the original nvm root to your new one
- Run
- Install Node using
nvm install latest
(currently v16.8.0 64bit)- Activate it using the command it shows when installation completes (eg
nvm use 16.8.0
) - Test the installation with
node -v
- Activate it using the command it shows when installation completes (eg
Install supporting tooling
- Install Postgres (Windows installer available here)
- Run the newly-installed PGAdmin to access the database server
- Add a new login (eg
phx
) for your upcoming app to use - If you use the default user from when you installed Postgres, that password could end up in source control!
- Add a new login (eg
- Install VS Code (Windows installer available here)
- Other editors/IDEs work fine, but I had to choose one for these instructions and VS Code is the most popular and widely used
- Add any required IDE extentions, for example Elixir support (
vscode-elixir-ls
)
Create and launch a sample application
As mentioned above in the Node installation section, due to the prevalence of beginner's material and existing projects being Phoenix < v1.6 these instructions assume the continued use of WebPack and Node and were written targetting Phoenix v1.5.12.
- Switch to wherever you keep code using
cd c:\Source\Elixir
- Create a sample app using
mix phx.new hello
- Navigate into it using
cd hello
- Avoid an about-to-occur node-gyp issue by using
cd assets && npm un node-sass && npm i sass && cd ..
to replace node-sasswith sass (which doesn't need node-gyp) - Install Node dependencies via
cd assets && npm i && node node_modules/webpack/bin/webpack.js --mode development && cd ..
- Configure the database with
notepad config/dev.exs
- Change the connection details to use the login you created in the Postgres section
- Set up the database with
mix ecto.create
- Optionally enhance the
.gitignore
file usingvi .gitignore
- Consider adding
/.idea/
,/.vs/
,/.vscode/
, and/or/.atom/
- Consider adding
- Add to source control with
git init && git add . && git commit -am "Initial commit" && git log
- Run it with
mix phx.server
- For the first run, use a command prompt/terminal in Administrator mode
- View it in the browser