A relatively concise guide to getting an easily upgradable Elm environment running on Mac.
At the end of this guide you'll have an environment that:
- can build from source
- is upgradable using only the command line
- can keep multiple versions of Elm around
The easiest way to try out Elm is by using the impressive online editor.
But at some point you'll likely feel the need to have a development environment all of your own.
While there is a nice Elm installer on Elm's web site, you may prefer, as I do, something that you can upgrade automatically from the command line and that builds from source.
If you're not interesting in building from source you can use npm in the directory of your project:
sudo npm install -g elm@<version>
to install globally or this if you want a specific version in some directory:
npm install elm@<version>
the executables will be in
Jump to What to do with your new Elm install to setup Sublime Text syntax highlighting and see what you can do with your newly installed Elm environment.
If you're reading this paragraph I assume you want to build from source and that your operating system is Linux or Mac. If it's Windows, you probably want to stick with the official installer or npm.
One confusing thing when one tries to install Elm from source is that it's written in Haskell, and installing Haskell is not particularly intuitive.
There is an official installer, the Haskell Platform, but, unless you're on Windows, I don't recommend it.
The ghc and cabal installed by Haskell Platform may be fiddly to eradicate if you want to switch to a command line friendly way of updating them.
The first stepping is getting halcyon:
$ eval "$( curl -sL https://github.com/mietek/halcyon/raw/master/setup.sh )"
see the halcyon tutorial for issues, but if you have bash 4.x it should be relatively straightforward.
If you have trouble you can visit #haskell-deployment on freenode and ask there.
Once halcyon is installed, install ghc and cabal with:
$ halcyon install
Update: for 0.17 you'll need newer cabal and ghc. For me cabal 184.108.40.206 and ghc 7.6.3 are working fine.
To install them:
$ HALCYON_GHC_VERSION=7.6.3 HALCYON_CABAL_VERSION=220.127.116.11 halcyon install
Now theoretically you should have a working set of cabal and ghc that will allow you to compile Elm from source.
As a rule I always try to use tools that allow me to keep more than one language version on the same machine, like rvm does for Ruby. Furtunately Elm has one, it's called Elmenv.
Installing elmenv takes a few steps, which I list here, straight from the install guide on github.
Elmenv should live in
~/.elmenv, so clone to that directory:
$ git clone --recurse-submodules https://github.com/sonnym/elmenv.git ~/.elmenv
To be able to use elmenv from the command line you'll have to add it to you path.
$ echo 'export PATH="$HOME/.elmenv/bin:$PATH"' >> ~/.bash_profile
will work if you're on Mac.
To get autocompletition also add the init command to your shell:
echo 'eval "$(elmenv init -)"' >> ~/.bash_profile
Source the changes to your shell, or start another shell:
To check that elmenv has been installed successfully:
$ type elmenv #=> "elmenv is a function"
Install Elm using elmenv
Now you can use elmenv to install Elm, compiling from source automatically.
$ elmenv install 0.14.1
will do the trick.
If you want to set a default version of elm to be used:
$ elmenv global 0.14.1
To set a specific version, to be used just in one project, cd into the project directory and execute
$ elmenv local 0.15.0
That's particularly handy because Elm is still making breaking changes between versions, and keeping an older version around will let you decide when to upgrade the project to a new Elm version, rather than being forced.
And with this your local Elm dev environment is done.
Next post: What to do with your new Elm install