Installing Elm on Ubuntu 14.04
Elm is a functional programming language for the web.
Elm lets you write programs in a simple functional language and it compiles to
CSS. This sounded like a cool way to learn about FRP (Functional Reactive Programming), so I decided to give it a try.
Because it’s a young language (the thesis which gave it birth was in 2012) it’s evolving fast, so dependencies and syntax are still changing.
We want to install the Elm-Platform which comes with all the tools to get started:
- elm-compiler: emm…. The compiler.
elm-make: Command line tool to turn your
- elm-reactor: This loads an interactive editor on the browser to evaluate and hot-swap code.
- elm-repl: a Read Eval Print Loop to play around with the language and explore libraries.
- elm-package: the package manager, to install/uninstall community packages.
Starting with the right version #
Elm 0.15.1 you will need Haskell and Cabal (the Haskell package manager). Currently you need
GHC 7.10 and at least
However installing them with
apt-get on Ubuntu will install an older version which won’t work (
cabal 188.8.131.52 and
So the first thing is to get a more recent version of Cabal and ghc
sudo add-apt-repository ppa:hvr/ghc sudo apt-get update
The packages install into
/opt/ghc/$VER/so in order to use them, the easiest way is to bring a particular GHC version into scope by placing the respective
/opt/ghc/$VER/binfolder early into the
PATHenvironment variable. See also https://github.com/hvr/multi-ghc-travis for more information
sudo apt-get install ghc-7.10.1 sudo apt-get install cabal-install-1.22
and add it to your
PATH variable (or add it to your .bashrc):
# Haskell & cabal Path export PATH=/opt/ghc/7.10.1/bin:$PATH export PATH=/opt/cabal/1.22/bin:$PATH
You should now see:
cabal --version cabal-install version 184.108.40.206 using version 220.127.116.11 of the Cabal library
which cabal /opt/cabal/1.22/bin/cabal
The Elm Platform #
- chose a directory to save all the files for your installation (but don’t create a directory). Let’s assume we want it to live at
~/Documents/code/(You should not move this directory after it is created, so choose carefully before progressing)
- add the absolute path
PATH. For our example above, this would be:
$ export PATH=/home/user/Documents/code/Elm-Platform/0.15.1/.cabal-sandbox/bin:$PATH
or you can add it to .bashrc or .bash_profile as described here.
- Let’s go to the directory we selected (in our example
$ cd ~/Documents/code), and run the haskell installation file:
# if you are on windows, or some other place without curl, just download this file manually curl https://raw.githubusercontent.com/elm-lang/elm-platform/master/installers/BuildFromSource.hs > BuildFromSource.hs runhaskell BuildFromSource.hs 0.15.1
You can test if your installed version is right with:
$ elm-make --help elm-make 0.2 (Elm Platform 0.15.1)
$ which elm-make /home/user/Documentos/code/Elm-Platform/0.15.1/.cabal-sandbox/bin/elm-make
Let’s try it out: #
let’s create a new directory,
mkdir helloworld && cd helloworld and create a
-- helloworld.elm import Html exposing (text) main = text "Hello, World!"
you can compile it with
elm-make which should create 3 files:
and check out the result in the browser with:
elm-reactor Elm Reactor 0.3.2 (Elm Platform 0.15.1) Listening on http://0.0.0.0:8000/