Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCaml: Can't run utop after installing it

I'm trying to learn OCaml through the Real World OCaml book. They have a guide by which I am supposed to install the Core package and utop. However, while I seem to be successfully installing both of these using Opam, neither of them works when I try to use them.

I know that they're installed, because when I try to install them again, I get this message:

$ opam install utop core
[NOTE] Package utop is already installed (current version is 1.10).
[NOTE] Package core is already installed (current version is 109.55.02).

However, when I try to enter "utop" to start utop, it doesn't work.

$ utop
bash: utop: command not found

Same when I try to open core:

$ open Core.Std
Couldn't get a file descriptor referring to the console

What's going on here? I'm new to programming so there might be something about installation that I'm just not understanding.

like image 254
akim330 Avatar asked Dec 23 '13 07:12

akim330


2 Answers

The methods to install OCaml utop in ubuntu in most of the online resources seem like kind of misleading users. The thing is when installing opam with sudo apt-get command there is no need to install OCaml again using same command because OCaml came with opam installation. so only thing you have to do is to correctly initialize the state of the opam which defines the OPAM root in your home folder.

So if you have installed any OCaml earlier first remove them to avoid conflicts.

sudo apt-get purge --auto-remove ocaml-source
sudo apt-get purge opam

then install opam.

sudo add-apt-repository ppa:avsm/ppa
sudo apt-get update
sudo apt-get install opam

initialize the state of the opam

opam init

if it shows a dependency missing warning try this commands,

opam install depext
opam depext conf-m4.1

then verify ocaml installation,

eval 'opam config env'
ocaml

install UTop then,

opam install utop
eval `opam config env`
utop

for detailed information and handle errors please refer this blog post.

like image 55
ThilankaD Avatar answered Nov 15 '22 01:11

ThilankaD


Regarding utop, it seems that you don't have in your $PATH. Did you do:

$ eval `opam config env`

If you want opam to be correctly automatically setup in your new shells you should add the following to your .bashrc:

. ~/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true

As for not being able to open Core.Std, you won't of course be able to open it in your shell, this command must be issued in utop.

like image 34
Daniel Bünzli Avatar answered Nov 15 '22 02:11

Daniel Bünzli