Codementor Events

Install ELM on Freebsd

Published Jan 09, 2018
Install ELM on Freebsd

What we want

To install ELM on Freebsd

Problem

There is no port for ELM.

So we can't use

pkg install something

nor

cd /usr/ports/lang/elm && make clean install

Solution

Install ELM from the source.

Pre-requisites

  • Having wget installed (if not => pkg install wget)

First step : Install Haskell/ghc

We need to install Haskell to compile the ELM sources.
The right version here is ghc 7.10.3 since the latest version cannot be used to install ELM v18

(Some of the following instructions have been retrieved from the great article on how to install ghc on freebsd : https://ryanglscott.github.io/2014/07/16/installing-ghc-on-freebsd/)
N.B. : Some adpatations have been made to meet the ELM install

Install and configure gcc:

# Install compatibility package
$ pkg install compat8x-amd64
# Install gcc
$ pkg install gcc
# it gives you gcc6

Download ghc archive (size is 72.76M):

$ cd /tmp
$ wget https://downloads.haskell.org/~ghc/7.10.3/ghc-7.10.3-x86_64-portbld-freebsd.tar.xz

Extract archive

$ tar -xf ghc-7.10.3-x86_64-portbld-freebsd.tar.xz
$ cd ghc-7.10.3

Make install ghc

$ env CC=gcc6 ./configure --with-gcc=gcc6 --with-ld=/usr/local/bin/ld
$ gmake install

Check that ghc and Haskell are well installed:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.3

$ runhaskell --version
runghc 7.10.3

Second step : Install CABAL

We need cabal to manage haskell packages (see https://www.freshports.org/devel/hs-cabal-install)

Install cabal package

$ pkg install hs-cabal-install

Third step : Build ELM from source

Create elm folder

$ mkdir -p /usr/local/elm
$ cd /usr/local/elm/

Get ELM source code

$ curl https://raw.githubusercontent.com/elm-lang/elm-platform/master/installers/BuildFromSource.hs > BuildFromSource.hs

Run haskell to build ELM from source

$ runhaskell BuildFromSource.hs 0.18 
# about 10 minutes... (yes, that long)

Last step : Configure path

Change Path to PATH="$PATH:/usr/local/elm/Elm-Platform/0.18/.cabal-sandbox/bin"

Last check:

$ elm --version
0.18.0

The end

Discover and read more posts from Julien Wazné
get started
post comments4Replies
DevRunner
6 years ago

While doing runhaskell BuildSource.hs 0.18, building led to some errors in Elm-Platform/0.18/src/Utils/Paths.hs.

Solution in this article :
http://lazyswamp.blogspot.com/2018/05/how-to-build-elm-platform-from-source.html

Thanks for the tips.

Peter Sagerson
6 years ago

Thanks for the tips. I expanded this into a makefile for reliably building Elm 0.18, including sandboxed builds of GHC 7.10.3 and Cabal 1.22.9.0. There’s also a script to produce a binary package for installation.

https://bitbucket.org/psagers/elm-freebsd

antranigv:~ %
7 years ago

a small issue here tho. when doing pkg install hs-cabal-install it will also install ghc-8, then when running runhaskell it will not work, complaining that "

You need GHC 7.10 to build this version of Elm.
You are using GHC 8.0 instead.

it’s better to set a prefix when gmake’ing ghc7 and then call it from there :)

thanks a lot! finally I can learn Elm!

Julien Wazné
7 years ago

Thank you antranigv !

Have fun with ELM !

Show more replies