Installing Elm on Ubuntu 14.04

Elm is a functional programming language for the web.

elm-logo.png

Elm lets you write programs in a simple functional language and it compiles to html, javascript and 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.

Installation #

We want to install the Elm-Platform which comes with all the tools to get started:

Starting with the right version #

To install Elm 0.15.1 you will need Haskell and Cabal (the Haskell package manager). Currently you need GHC 7.10 and at least cabal 1.18.

However installing them with apt-get on Ubuntu will install an older version which won’t work (cabal 1.16.0.2 and ghc 7.6.3).

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/bin folder early into the PATH environment 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 1.22.6.0
using version 1.22.4.0 of the Cabal library 
which cabal
/opt/cabal/1.22/bin/cabal

The Elm Platform #

  1. 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)
  2. add the absolute path Elm-Platform/0.15.1/.cabal-sandbox/bin to your 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.

  1. 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)

or

$ 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 file.

-- helloworld.elm
import Html exposing (text)
main =
  text "Hello, World!"

you can compile it with elm-make which should create 3 files:

elm-package.json elm-stuff helloworld.elm

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/

Have fun!

 
48
Kudos
 
48
Kudos

Now read this

Open thank you to open source

My life and career have lead me to learn languages and jargon. They have been the foundation to build sucessful research or relationships. After 3 years slowly walking towards starting my own company, I notice a new language and culture... Continue →