# How to install modules

**URL:** <https://discourse.haskell.org/t/how-to-install-modules/1363>\
**Category:** Learn\
**Created:** [August 12, 2020, 8:35am UTC](https://discourse.haskell.org/t/how-to-install-modules/1363 "2020-08-12T08:35:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hautor](https://avatars.discourse-cdn.com/v4/letter/h/13edae/32.png) [@hautor](https://discourse.haskell.org/u/hautor)\
**Post date:** [August 12, 2020, 8:35am UTC](https://discourse.haskell.org/t/how-to-install-modules/1363/1 "2020-08-12T08:35:26Z")

</div>

Hello. I’m a beginner in Haskell. I want to install modules (for example System.Random), but I dont’ know how to do it. Some easy instructions?

---

<div class="post-metadata">

**Author:** ![palik](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/palik/32/32_2.png) [@palik](https://discourse.haskell.org/u/palik)\
**Post date:** [August 12, 2020, 9:11am UTC](https://discourse.haskell.org/t/how-to-install-modules/1363/2 "2020-08-12T09:11:14Z")

</div>

`cabal install random`

[https://www.haskell.org/cabal/](https://www.haskell.org/cabal/)

---

<div class="post-metadata">

**Author:** ![danidiaz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/danidiaz/32/92_2.png) [@danidiaz](https://discourse.haskell.org/u/danidiaz)\
**Post date:** [August 12, 2020, 3:23pm UTC](https://discourse.haskell.org/t/how-to-install-modules/1363/3 "2020-08-12T15:23:26Z")

</div>

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:

- [the cabal install section of the Cabal User Guide](https://cabal.readthedocs.io/en/3.4/cabal-commands.html#cabal-v2-install).

- [the GHC User Guide on how package environment files work, and where do GHC and ghci look for them.](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/packages.html#package-environments)

---

<div class="post-metadata">

**Author:** ![jaror](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/jaror/32/3271_2.png) [@jaror](https://discourse.haskell.org/u/jaror)\
**Post date:** [August 13, 2020, 12:23pm UTC](https://discourse.haskell.org/t/how-to-install-modules/1363/4 "2020-08-13T12:23:04Z")

</div>

> [@danidiaz](#):
>
> 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.

Note that this can cause conflicts (e.g. [Cannot satisfy -package-id X11-1.9.1-As84WI1VImVHquwEDPbrTE - #9 by jaror](http://discourse.haskell.org/t/cannot-satisfy-package-id-x11-1-9-1-as84wi1vimvhquwedpbrte/1294/9)), so the package-env method should be preferred.

---

<div class="post-metadata">

**Author:** ![hautor](https://avatars.discourse-cdn.com/v4/letter/h/13edae/32.png) [@hautor](https://discourse.haskell.org/u/hautor)\
**Post date:** [August 15, 2020, 8:15am UTC](https://discourse.haskell.org/t/how-to-install-modules/1363/5 "2020-08-15T08:15:50Z")

</div>

Thank you very much. It works!

---

<div class="post-metadata">

**Author:** ![maliky](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/maliky/32/2819_2.png) [@maliky](https://discourse.haskell.org/u/maliky)\
**Post date:** [December 14, 2022, 6:57pm UTC](https://discourse.haskell.org/t/how-to-install-modules/1363/6 "2022-12-14T18:57:11Z")

</div>

I want to install `System.Random` too.  
The answers you give above work, I’m sure but I tried using `cabal list System.Random` and instead of clarifying the exact name of the module to use, cabal listed tens of modules with similar names. I was enable to know which module was from the `System` and which are made by some other peers.

How do I know that the package listed with `cabal list` is from the `System` library ?

---

<div class="post-metadata">

**Author:** ![hasufell](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/hasufell/32/1250_2.png) [@hasufell](https://discourse.haskell.org/u/hasufell)\
**Post date:** [December 15, 2022, 2:18am UTC](https://discourse.haskell.org/t/how-to-install-modules/1363/7 "2022-12-15T02:18:19Z")

</div>

This is also described here: [First steps - GHCup](https://www.haskell.org/ghcup/steps/#using-external-packages-in-ghci)
