22

Over here is the only reason I can find that packages I'm installing using cabal are not being found by GHC:

This happens when you install a package globally, and the previous packages were installed locally. Note that cabal-install install locally by default [...]

Presumably, "local installation" means putting packages in ~/.cabal/. First question: where are global installs?

I've been running cabal using sudo, so I guess that's a global install? The reason I've been doing this is that it complains about permissions when run without sudo, so this contradicts the statement "cabal-install install locally by default". Second question: how do I install locally and how do I install globally?

Trying to fix this mess, I've been randomly using sudo ghc-pkg unregister and randomly removing stuff from ~/.cabal/. Consequently my package tree is broken, probably locally and globally. Third question: How do I start again?


Edit: I'm running Ubuntu 10.10. I installed the Haskell Platform 2011.

jameshfisher
  • 34,029
  • 31
  • 121
  • 167
  • What platform are you on and what specific error messages are you getting? It could be that by running cabal as root (sudo) you've installed all the packages locally for the root user in /root/.cabal (assuming some version of Linux). – asm Jun 02 '11 at 11:54

1 Answers1

9

Are you using Windows, OS X or some version of Linux? Are you using the Haskell Platform? Have you had a version of ghc or cabal before? For a Linux distribution, subtleties about your package manager may come in, of course. (Traces of an old ghc in particular, and an old ~/.ghc/ directory can be a source of trouble.)

Here are a few elementary thoughts of the type one goes through on #haskell with such problems. (My comprehension is not completely adequate, of course):

The chief question seems to be, Why you were being invited to do what should be local installs with sudo? A global install (cabal install pony --global) would of course require privileges if ghc and its libraries are in /usr/... or some other protected place, but otherwise sudo vs non-sudo is independent of the place of installation. What you do with cabal install pony --user (--user is the default, in theory) should not require superuser authority. (I have sometimes found on OS X that privileges are requested where the gcc needs to be called, but this has usually been due to curiosities about my setup.) But in any case sudo doesn't affect where cabal is putting them: the implicit --user and explicit --global, and more specific incantations for development, do that.

If you do ghc-pkg list, for example, it will divide the packages into the different places they are registered in according to two or more package.conf.d directories it is summarizing. On my laptop at the moment these are

/Users/applicative/.ghc/x86_64-darwin-7.0.3/package.conf.d/... 

for the local things in ~/.cabal/lib/... and the protected

/Library/Frameworks/GHC.framework/Versions/7.0.3-x86_64/usr/lib/ghc-7.0.3/package.conf.d 

for things that were installed globally with the Haskell Platform installer (this location involves some OS X peculiarities, ghc, ghci and so on are in the woods somewhere, but symlinked to /usr/bin). The conf files for different packages tell you exactly where the libraries were installed. So, for example about the sacred base library,

$ cat base-4.3.1.0-f5c465200a37a65ca26c5c6c600f6c76.conf

tells me:

import-dirs:
 /Library/Frameworks/GHC.framework/Versions/7.0.3-x86_64/usr/lib/ghc-7.0.3/base-4.3.1.0
library-dirs: 
 /Library/Frameworks/GHC.framework/Versions/7.0.3-x86_64/usr/lib/ghc-7.0.3/base-4.3.1.0

In any case, where does ghc-pkg list say your cabal install-ed packages are going? In the ~/.cabal folder, look at the file config. If you haven't edited it, I think the commented and uncommented lines, if they state a preference, are stating the defaults for installation with --global and --user. In the ~.ghc/ directory check out the subdirectory myghcversion/package.conf.d and see if anything is there, which should be the same as what ghc-pkg tells you. (You might study the options for ghc-pkg in general, eg. ghc-pkg check and ghc-pkg recache, if you haven't. You may have installed something in some odd way.)

If you installed ghc and cabal and co. by installing the Haskell Platform with a binary installer or your package manager, which seems like a good idea, it is also a good idea, I think, to keep the Platform libraries as something sacred, and make sure you never install anything globally from Hackage; among other things this is likely to have you overwriting Platform libraries -- though this doesn't seem the difficulty here: it would be more obvious if it were.

applicative
  • 8,081
  • 35
  • 38
  • Wow, big answer, thanks. Away from machine ATM, will follow up in a few days. So: it's not usual for `cabal install foo` to require `sudo`? It is definitely installing *things* under `~/.cabal/`; I assumed `sudo` was required because local install does *something* global. Is this not the case? – jameshfisher Jun 02 '11 at 17:06
  • Not normally no. I'm not sure if ubuntu has a /root directory or not but if it does I would check there and see if there are packages in a .cabal directory. – asm Jun 02 '11 at 19:30
  • 1
    ah... I was going mad. removing ~/.ghc finally did it. On ubuntu, I uninstalled haskell-platform and cabal-install, then removed ~/.cabal and finally ~/.ghc, and updated apt-get, then install them again. My broken setup is finally fixed, and I successfully did a cabal install idris. It is common sense to run cabal with sudo because many instructions to run apt-get are ambiguous about sudo as well, which I initially did as well; but I immediately noticed that cabal looks a lot like opam, which does install everything per-user. – Rob Apr 04 '14 at 05:10