# Unbound module Base, unbound directive require

**URL:** <https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196>\
**Category:** Learning\
**Created:** [July 25, 2021, 7:31am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196 "2021-07-25T07:31:35Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![gefei](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gefei](https://discuss.ocaml.org/u/gefei)\
**Post date:** [July 25, 2021, 7:31am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/1 "2021-07-25T07:31:35Z")

</div>

This has been asked before, but the answers there do not solve my problem:

```auto
$ ocaml
        OCaml version 4.12.0

# open Base;;
Error: Unbound module Base
# require "base";;
Error: Unbound value require
# #require "base";;
Unknown directive `require'.
#

```

Can anyone help?

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [July 25, 2021, 7:50am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/2 "2021-07-25T07:50:36Z")

</div>

Try doing (assuming you have installed `base` in your system):

```auto
# #use "topfind";;
# #require "base";;

```

(note the leading `#` before `use` and `require`).

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![gefei](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gefei](https://discuss.ocaml.org/u/gefei)\
**Post date:** [July 25, 2021, 7:58am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/3 "2021-07-25T07:58:02Z")

</div>

Unfortunately it does not help.

```auto
# #use "topfind";;
Cannot find file topfind.
# #require "base";;
Unknown directive `require'.

```

I wonder why it does not even know “require”

BTW, my ocaml had been installed on my Mac by  
`brew install ocaml`

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [July 25, 2021, 8:02am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/4 "2021-07-25T08:02:44Z")

</div>

> [@gefei](#):
>
> BTW, my ocaml had been installed on my Mac by  
> `brew install ocaml`

In that case you will need to install `findlib` first. Try doing

```auto
brew install ocaml-findlib

```

and retrying the above.

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [July 25, 2021, 8:29am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/5 "2021-07-25T08:29:56Z")

</div>

By the way, the recommended way to install `ocaml` nowadays is to use [`opam`](https://opam.ocaml.org/). If you have `opam` installed, you can just do `opam install base` to install the `base` library and then everything should work.

You can install `opam` on OS X by doing `brew install opam`.

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![gefei](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gefei](https://discuss.ocaml.org/u/gefei)\
**Post date:** [July 25, 2021, 8:32am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/6 "2021-07-25T08:32:19Z")

</div>

Thanks. I am getting further, but …

```auto
# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";; to load a package
  #list;; to list the available packages
  #camlp4o;; to load camlp4 (standard syntax)
  #camlp4r;; to load camlp4 (revised syntax)
  #predicates "p,q,...";; to set these predicates
  Topfind.reset();; to force that packages will be reloaded
  #thread;; to enable threads

- : unit = ()
# #require "base";;
No such package: base

```

It still does not find `base` …

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [July 25, 2021, 8:33am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/7 "2021-07-25T08:33:29Z")

</div>

> [@gefei](#):
>
> It still does not find `base` …

You need to install it, it does not come with the compiler. The easiest way to install it is to use `opam` (see my [previous message](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/5).

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![gefei](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gefei](https://discuss.ocaml.org/u/gefei)\
**Post date:** [July 25, 2021, 8:46am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/8 "2021-07-25T08:46:37Z")

</div>

It still does not work …

```auto
$ opam install base
[NOTE] Package base is already installed (current version is v0.14.1).
$ ocaml
        OCaml version 4.12.0

# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";; to load a package
  #list;; to list the available packages
  #camlp4o;; to load camlp4 (standard syntax)
  #camlp4r;; to load camlp4 (revised syntax)
  #predicates "p,q,...";; to set these predicates
  Topfind.reset();; to force that packages will be reloaded
  #thread;; to enable threads

- : unit = ()
# #require "base";;
No such package: base

```

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [July 25, 2021, 8:57am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/9 "2021-07-25T08:57:04Z")

</div>

It may be that you now have two different `ocaml` installations: that of `opam` and that of `brew`. To make sure you are using the one from `opam`, type

```auto
eval $(opam env)

```

and try again.

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![gefei](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gefei](https://discuss.ocaml.org/u/gefei)\
**Post date:** [July 25, 2021, 9:28pm UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/10 "2021-07-25T21:28:49Z")

</div>

Nope …

```auto
$ eval $(opam env)
$ ocaml
        OCaml version 4.12.0

# #use "topfind";;
- : unit = ()
Findlib has been successfully loaded. Additional directives:
  #require "package";; to load a package
  #list;; to list the available packages
  #camlp4o;; to load camlp4 (standard syntax)
  #camlp4r;; to load camlp4 (revised syntax)
  #predicates "p,q,...";; to set these predicates
  Topfind.reset();; to force that packages will be reloaded
  #thread;; to enable threads

- : unit = ()
# #require "base";;
No such package: base

```

Thanks a lot for your help, Nicolas, I really appreciate it. Meanwhile, I think I’d better try my luck with another language. There are many functional languages after all

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [July 25, 2021, 9:51pm UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/11 "2021-07-25T21:51:30Z")

</div>

What’s the output of `ocamlfind printconf` ?

Cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [July 26, 2021, 1:21am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/12 "2021-07-26T01:21:04Z")

</div>

What’s the output of:

```auto
$ opam list

```

Is `base` listed in the output? If so, then it is definitely installed in the current opam switch. If not, you need to install it with: `opam install base`.

Finally, it is recommended to use the enhanced OCaml REPL, utop:

```auto
$ opam install utop
$ utop
utop # #require "base";;

```

`utop` automatically loads findlib for you and provides other conveniences as well, like autocomplete, and history.

---

<div class="post-metadata">

**Author:** ![gefei](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gefei](https://discuss.ocaml.org/u/gefei)\
**Post date:** [July 26, 2021, 3:51am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/13 "2021-07-26T03:51:47Z")

</div>

```auto
$ ocamlfind printconf
Effective configuration:
Configuration file:
    /usr/local/etc/findlib.conf
Search path:
    /usr/local/lib/ocaml
Packages will be installed in/removed from:
    /usr/local/lib/ocaml
META files will be installed in/removed from:
    the corresponding package directories
The standard library is assumed to reside in:
    /usr/local/lib/ocaml
The ld.conf file can be found here:
    /usr/local/lib/ocaml/ld.conf

```

---

<div class="post-metadata">

**Author:** ![gefei](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gefei](https://discuss.ocaml.org/u/gefei)\
**Post date:** [July 26, 2021, 3:52am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/14 "2021-07-26T03:52:24Z")

</div>

```auto
$ opam list
# Packages matching: installed
# Name # Installed # Synopsis
base v0.14.1 Full standard library replacement for OCaml
base-bigarray base
base-threads base
base-unix base
csexp 1.5.1 Parsing and printing of S-expressions in Canonical
dune 2.9.0 Fast, portable, and opinionated build system
dune-configurator 2.9.0 Helper library for gathering system configuration
ocaml 4.12.0 The OCaml compiler (virtual package)
ocaml-config 2 OCaml Switch Configuration
ocaml-system 4.12.0 The OCaml compiler (system version, from outside o
result 1.5 Compatibility Result module
sexplib0 v0.14.0 Library containing the definition of S-expressions

```

---

<div class="post-metadata">

**Author:** ![gefei](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gefei](https://discuss.ocaml.org/u/gefei)\
**Post date:** [July 26, 2021, 4:00am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/15 "2021-07-26T04:00:47Z")

</div>

> [@yawaramin](#):
>
> Finally, it is recommended to use the enhanced OCaml REPL, utop:
> 
> ```auto
> $ opam install utop
> $ utop
> utop # #require "base";;
> 
> ```

Finally, this works! Thanks!

---

<div class="post-metadata">

**Author:** ![shonfeder](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/shonfeder/32/424_2.png) [@shonfeder](https://discuss.ocaml.org/u/shonfeder)\
**Post date:** [July 26, 2021, 11:43am UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/16 "2021-07-26T11:43:21Z")

</div>

Hi, @gefei ! Would you mind sharing what learning material or documentation you were using to get oriented and set up with OCaml? It sounds like we’ll want to update or deprecate it (as appropriate), so we can save future users from the pain of going down tough set up paths.

---

<div class="post-metadata">

**Author:** ![gefei](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@gefei](https://discuss.ocaml.org/u/gefei)\
**Post date:** [July 28, 2021, 5:29pm UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/17 "2021-07-28T17:29:13Z")

</div>

Hi @shonfeder I was learning OCaml by the book “Real world ocaml” [https://dev.realworldocaml.org/](https://dev.realworldocaml.org/), and I had problem with the very first line in the first example which reads `open Base;;`

---

<div class="post-metadata">

**Author:** ![shonfeder](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/shonfeder/32/424_2.png) [@shonfeder](https://discuss.ocaml.org/u/shonfeder)\
**Post date:** [July 28, 2021, 5:32pm UTC](https://discuss.ocaml.org/t/unbound-module-base-unbound-directive-require/8196/18 "2021-07-28T17:32:02Z")

</div>

Thanks! I looks like RWO advises installing from opam. Is it possible you’d consulted different material initially for the installation, that advised installing from homebrew?
