Installing Haskell packages on Mac
Asked Answered
T

7

29

I can't seem to get a few Haskell packages to install on my Mac (10.6.8). I first tried Happstack and it failed and then I tried Snap.

Sometimes when I run ghci I get a segmentation fault.

Other times it works and goes like this:

GHCi, version 7.4.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude>

When trying to get Snap:

....
....
....
Loading package vector-0.10.0.1 ... linking ... done.
Loading package zlib-0.5.4.0 ... linking ... done.
Loading package zlib-bindings-0.1.1.3 ... linking ... done.
Loading package zlib-enum-0.2.3 ... linking ... done.
Loading package snap-core-0.9.3.1 ... linking ... done.
Loading package snap-server-0.9.3.3 ... linking ... done.
Loading package directory-tree-0.11.0 ... linking ... done.
cabal: Error: some packages failed to install:
snap-0.11.2 failed during the building phase. The exception was:
ExitFailure 11

I have seen this problem a few times but nothing really solved it for me. Any ideas?

Transude answered 29/3, 2013 at 18:23 Comment(5)
cabal install -v2 snap should give more information about the cause of the build failure.Pontone
Thanks. I just ran that and got: pastebin.com/Wf7gASwK I am still not exactly sure.Transude
Unfortunately not very informative. You could try cabal unpack snap, and then cabal configure && cabal build in the unpacked directory. But, I hadn't seen "Sometimes when I run ghci I get a segmentation fault." originally, that suggests your GHC is broken. If that is the case, it may not be the package's fault. How did you install GHC?Pontone
have you tried ghc-pkg check yet. It will check for broken packages. If it is a package you have install through cabal you can unregister it with ghc-pkg unregister <package> and install it again which should fix it. If the package is part of ghc they you can reinstall ghc(there should be a better solution but I have not had time to explore/find it.)Pylon
Are you using 32bit or 64bit GHC? I believe I used to see this problem when using 64bit, and that it went away when I switched to 32bit.Mouseear
Y
43

Updated May 22, 2021

Have you tried using homebrew? It handles the dependencies for you.

Using homebrew, you can use the brew command to install ghc and cabal-install.

$ brew install ghc cabal-install
==> Downloading https://ghcr.io/v2/homebrew/core/ghc/manifests/8.10.4
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ghc/blobs/sha256:965f94c14b56e3db7b239860e0a1d577be0b27caf8adb6212710a7430ce723d3
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:965f94c14b56e3db7b239860e0a1d577be0b27caf8adb6212710a7430ce723d3?se=2021-05-23T05%3A15%3A00Z&sig=fkH7sUY44VCLV8hI%2BtZT%2B
######################################################################## 100.0%
==> Pouring ghc--8.10.4.big_sur.bottle.tar.gz
==> /usr/local/Cellar/ghc/8.10.4/bin/ghc-pkg recache
🍺  /usr/local/Cellar/ghc/8.10.4: 6,907 files, 1.5GB
==> Downloading https://ghcr.io/v2/homebrew/core/cabal-install/manifests/3.4.0.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/cabal-install/blobs/sha256:2c0c5cc90d4739515721557f8e9c02783b3b5f106033c5c09241657b4418b21f
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:2c0c5cc90d4739515721557f8e9c02783b3b5f106033c5c09241657b4418b21f?se=2021-05-23T05%3A15%3A00Z&sig=O7ylxHgq42YVADlzTacdRfY7W
######################################################################## 100.0%
==> Pouring cabal-install--3.4.0.0.big_sur.bottle.tar.gz
🍺  /usr/local/Cellar/cabal-install/3.4.0.0: 7 files, 39.6MB

Once installed, you should be able to run:

$ ghc
ghc: no input files
Usage: For basic information, try the `--help' option.

As well as the Haskell interpreter, ghci:

$ ghci
GHCi, version 8.10.4: https://www.haskell.org/ghc/  :? for help
Prelude>

Hope this helps!

Yeomanry answered 29/3, 2013 at 18:49 Comment(2)
Having been in the GHC-7.4-with-Snow-Leopard boat (and the using-Homebrew-for-simplicity boat), I must unfortunately tell you that this won't help. OS X 10.6 is just too old for GHC 7.4. I've shared what I learned from my experience in my answer.Doughty
you should now use brew install ghc cabal-install insteadPointing
K
30

brew install haskell-platform is no longer supported. You may want to

Error: No available formula for haskell-platform
We no longer package haskell-platform. Consider installing ghc and cabal-install instead:
brew install ghc cabal-install

Knutson answered 11/9, 2014 at 17:22 Comment(2)
brew install ghc cabal-install worked for me just as brew advises. NOTE: the final part of the install took 21 minutes on my fast broadband. So just go make a cup of tea.Roomy
Downloaded in 30 seconds for me (45 Mbps), installed in 15 seconds. That 21 minutes was probably building, not download. Why would there be such a huge difference for us?Oliva
M
13

Since haskell-platform on homebrew for Mac is deprecated, you can use brew install ghc cabal-install instead. I did it on Yosemite and it took about one minute…

> $ brew install ghc cabal-install                                             
==> Downloading https://homebrew.bintray.com/bottles/ghc-7.10.1_1.yosemite.bottl
######################################################################## 100.0%
==> Pouring ghc-7.10.1_1.yosemite.bottle.tar.gz
🍺  /usr/local/Cellar/ghc/7.10.1_1: 5423 files, 821M
==> Downloading https://homebrew.bintray.com/bottles/cabal-install-1.22.2.0.yose
######################################################################## 100.0%
==> Pouring cabal-install-1.22.2.0.yosemite.bottle.1.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/cabal-install/1.22.2.0: 6 files, 19M
Makkah answered 19/6, 2015 at 9:17 Comment(0)
O
11

This is an old question but given it comes quiet high on Google search. This is how I got here.

$ brew update
$ brew install haskell-stack
$ stack --version
$ stack --help # "man stack" gives something completely different
$ stack setup # Install GHC
$ stack ghci

Source: http://seanhess.github.io/2015/08/04/practical-haskell-getting-started.html

Why stack and not cabal?

Edit:

I found annoying to have to write "stack ghci" each time I wanted to use "ghci". A solution to this was to simply add these lines to the ~/.bash_aliases file:

alias sghc='stack ghc'
alias sghci='stack ghci'
alias srunhaskell='stack runhaskell'

Then source the file to apply:

$ source ~/.bash_aliases

Then I can run ghci and / or haskell running these commands, and it will use the stack version:

$ sghc [filename]
$ sghci
$ srunhaskell
Obsecrate answered 6/2, 2016 at 1:0 Comment(0)
P
7

Update: February 2016: Whilst other answers were helpful, I didn't find a complete, up-to-date answer.

The install is easy:

$ brew install ghc cabal-install

An extra step I needed to perform post-install was:

$ cabal update

followed by:

$ cabal install ghc-mod

See here for details.

haskell install

Alternatively, instead of using homebrew for the install, visit Haskell Platform for the installer disk image - note that Haskell Platform is only compatible with OS X 10.6 and later.

Although, as a general rule I always use homebrew to manage my dependencies, when it comes to Haskell my recommendation (unless you really know what you are doing) is to just install this binary. This avoids any surprises further down the road. There is excellent documentation post install locally at: file:///Library/Haskell/doc/start.html

The popular answer to this question (using brew to install haskell-platform) is no longer supported.

not supported

Probably answered 10/2, 2016 at 23:53 Comment(0)
D
5

Unfortunately, GHC 7.4 isn't supported on OS X 10.6; the download page only has an installer for 10.7, and as you can see, they mean it. I know your problem from bitter experience—I was in exactly your boat for a good long while, and I never found a solution other than upgrading Mac OS X (or, presumably, downgrading GHC, but I didn't really want to do that). A colleague of mine did manage to get 7.4.1 running on OS X 10.5, but it took nontrivial effort on her part (she had to use a different version of GMP, namely 5.0.5, and edit GHC's configure script), and I never tried to replicate it myself.

In the end, you have four options, in roughly decreasing order of simplicity:

  1. Use an older Haskell Platform. This means downgrading to GHC 7.0.x (not GHC 7.2.x—that was never in the Platform); there's not a good record of which GHC versions were in which package versions, though. Wikipedia implies that 2011.2 was the first version with GHC 7.0.x and that 2012.2 was the first version with GHC 7.4.x, so I'd try 2011.4.0.0 first.
  2. Install GHC 7.2 (which is supported on OS X) on its own, and forgo the Haskell Platform. This can cause headaches, but is possible. Don't forget to install Cabal, cabal-install, all the packages that come with the platform, etc.
  3. Upgrade to OS X 10.7 or 10.8, if you feel like a more global (and pricier) change.
  4. Try to replicate what my colleague did. (Best of luck, but it's definitely possible.)
Doughty answered 1/4, 2013 at 3:39 Comment(0)
M
2

Late 2017 answer. I'm running macOS Sierra -- 10.12.6 (16G29). This worked successfully with an install time on my MacBook Air of under five minutes:

brew cask install haskell-platform

Then ghc --version reported:

The Glorious Glasgow Haskell Compilation System, version 8.2.1

Magee answered 22/10, 2017 at 3:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.