How to install modules

Ensure that cabal --version is >= 3.

In an empty folder, type

cabal install --lib --package-env . random

That should create a file named .ghc.environment.<somemorestuff> in the folder.

In that same empty folder, start ghci:

ghci

Some message like “Loaded package environment from…” should appear when starting.

Inside ghci, import System.Random.

Prelude> import System.Random

If, when installing the package, you omit the location of the package environment:

cabal install --lib random

then it updates a default package environment located somewhere in your home directory.

With a bit of luck, ghci invocations should pick this default environment, too, but explicitly writing –package-env . is more foolprof.

Some relevant links:

7 Likes