I got both ghc6 and ghc7 on my desktop. To install new packages (for the specific ghc version), I use cabal
with the flag --with-compiler=<ghc-dir>
to specify for which ghc i want the package installed.
I do cabal update
before installing any new package. But how to I specify for which ghc I want the update? I mean, there is no --with-compiler
flag as with cabal install
. I would think that just like I use ghc-pkg7
for ghc7, there would be cabal7
. Apart from the cabal install
command which I know to which ghc version it is applying, I don't know which ghc is affected with the other cabal commands.
Also, when I do ghc-pkg check
I find problems with some packages and I don't know how to fix.
I would really like to know - if anyone does have - good practices when using multiple ghc versions on the same machine. e.g. how to proceed with installation, updates, etc.
cabal update
has no--with-compiler
option because it is completely compiler-agnostic -- it doesn't involve GHC or any other compiler at all. It just downloads a list of available packages from Hackage, nothing more. You can expect that something similar applies to other commands which do not let you choose a compiler (as the dev team was careful to avoid making cabal GHC-specific, let alone specific to a particular GHC version, wherever that makes sense).I thought
--with-ghc
is the appropriate option. I use to have multipleghc
versions on my machine. They all have different names likeghc-6.12.3
orghc-7.4.1
. They are usually installed with these names and a default compiler is chosen by creating symbolic links from, say,ghc
toghc-7.4.1
. I think you do not need different cabal directories for differentghc
versions. Cabal creates aghc-6.12.3
subdirectory oflib/yourpkg
forGHC-6.12.3
files and so on. Alsocabal update
does not update installed packages, it only fetches the current package list from your favorite package servers. This should be the same for all installed compilers.You can create two configuration files, say
~/.cabal/config
and~/.cabal/config7
, and use the un(der)documented option--config-file
to select between the two.This answer serves to complement the other answers (that are already enlightening).
First of all, know that there are significant differences between minor versions of GHC. For example, the change from GHC 7.8 to GHC 7.10 (cf. burning bridges proposal). So, it might be better to name your GHC binaries also including minor version numbers, like:
ghc7.8
andghc7.10
.Supposing you have several GHCs installed with the following names:
For GHC 7.8, you can create a file called
~/.cabal-ghc-7.8/config
with the following contents (that point to the locations described above):You can create an executable possibly called
cabal-ghc-7.8
in yourPATH
(it uses the--config-file
option described in n.m.'s answer):Now, in your cabalized source dir, you can simply run
cabal-ghc-7.8 build
to build your source files using GHC 7.8. (orcabal-ghc-7.8 test
or anything else)You can repeat the process for all the GHCs you have installed. Of course, you should not worry about the standard named GHC. By default, Cabal searches for a GHC named
ghc
.This answer assumes a UNIX/Linux system (like the use of
bash
), but can be adapted to other systems with small changes.Now (cabal version 1.24.0.0), one can
to install packages separately for multiple different GHCs.
(The meta-variable
path-to-ghc-executable-i
can be, like,/usr/bin/ghc-7.10.3
,/usr/local/bin/ghc-8.4.3
etc.)How did I know? This command can be found via https://www.haskell.org/cabal/users-guide/installing-packages.html or
cabal install --help
.The post-condition looks like this: I installed
QuickCheck
forghc-8.0.1
andghc-6.12.1
, then~/.cabal/lib
looks like: