Mac Install questions

So it appears you might not know the Unix command line very well, which certainly isn’t a sin, but it does mean you’re going to have to be very very careful about what you type and asking questions.

I’m a big believer in not doing things blindly, so let me explain what that command is.

In the current instance, what eval $(opam config env) does is this:

First of all, the shell $(command) construct, which is a newfangled version of the old fashioned bourne shell backquote construct, says: “run this command, take the stdout output, and insert it back into the command line as arguments to another command”.

So the command was taking the output of opam config env and making it into arguments to the eval command.

If you type opam config env on the command line, you’ll see it spits out a series of shell variable assignments and exports. The eval command (which you can read about in the sh or bash man page) then executes those assignments within the existing instance of the shell.

So what this is doing for you is setting a long set of shell environment variables so that the various ocaml tools will have everything from their PATH to their CAML_LD_LIBRARY_PATH set correctly when you use things in the ocaml ecosystem.

BTW, if you’re not a shell aficionado, you might not know that you can do things like:

opam install foo --verbose > /tmp/logfile 2>&1

This will save both stdout and stderr from that command into the file /tmp/logfile, which you can then examine at your leisure after it blows up.

BTW, if anyone can tell me why opam config env sets PERL5LIB I’d be interested in knowing. I’d never noticed that before, and I note the directory it points at is (in any case) non-existent. :slight_smile:

Because of this

That makes sense now, thanks @dbuenzli!

I dealt with this same problem when introducing my daughter to OCaml. After
struggling with Atom for a while, I ended up selling on Visual Studio Code.
It was simple to set up: there’s just one package for supporting OCaml, and
it works out of the box with ocp-indent and Merlin.

If you want Merlin to really work well, I recommend using jbuilder as the
build tool, since it generates the necessary .merlin file. The only serious
issue I ran into is that when the Merlin file changes you need to restart
Merlin explicitly to get it to pick up the new libraries you’ve added to
your namespace.

As for toplevels, is recommend utop, which has autocompletion and syntax
highlighting, as well as nice integration with jbuilder, so you can use it
to start a utop with access to the same libraries your project has access



So it appears you might not know the Unix command line very well, which certainly isn’t a sin, but it does mean you’re going to have to be very very careful about what you type and asking questions.

I feel so young again. :slight_smile:

Actually, there’s a pretty good chance, given the demographics of the world, that I was using the Unix command line before you were born. (I started in … uh…1975 or maybe early 1976; it was, I think, Unix version 2).

What I meant was that I had no idea what “opam” commands do generally. Most shell stuff I’m OK with. On the other hand, my eyesight isn’t so great, so I missed the “eval” on the line in question, and as you say, the "$( … )$ construct is comparatively new, and my shell knowledge is old and hoary.

In general, before I do something like “eval `opam config env`”, I run the inner command redirected to a file to see what it’s planning to do. I may not be cautious about my path, but I do worry about some potential gotchas.

Thanks again for your help (and for teaching me a few new things as well)!

1975 would have already been v6. There is little chance you used v2, only the developers of Unix ever saw that one, and v2 was still written in assembler, C only appearing for v4.

I was already around at that time, but I wasn’t really using computers until the late 1970s (a PDP-8e was my gateway drug), though I’d read a Fortran IV intro before that.

The opam man page will explain a great deal for you then. You will want to read it.

(The OCaml documentation isn’t always very good, but the man pages for the command line tools are quite complete, and I recommend reading them. There’s useful things in there.)

Generally, the opam tool works a great deal like most other modern package managers — it feels a lot like brew, or macports, or apt, or gem, or any other package manager you’ve probably dealt with. Similar style of commands, similar method of operation.

I also recommend poking about in your .opam directory so you get a feel for what is going on behind the scenes.

I think you got the list of commands slightly wrong:

  1. Install homebrew
  2. brew install opam
  3. brew install ocaml opam update && opam switch 4.05.0
  4. opam init
  5. eval opam install ocp-indent opam install ocp-indent
  6. setup Atom

Specifically, the eval in your step 7 seems unnecessary (and potentially problematic).
In my list, you might have to reverse steps 4 and 3.

1 Like

The eval in his step 7 is bizarre. I don’t think he can have gotten that from the normal instructions.

It IS bizarre, but for silly reasons: I messed up copy/pasting and trying to make thing appear in “preformatted” mode. (The eval was its own step, involving “eval”-ing something with back-ticks, which didn’t play nice with preformatting until I (later) figured out about escaping just enough of them. Apparently at some point during that experimenting, I deleted some stuff by accident.)

I assume I’ve come across this question too late to be of use to you but I use OCaml with Atom in a couple of classes and my installation instructions seem to work ~50 first-year students have it up and running. The instructions are presently in a private repo but I can make a public copy if you want to see it.
Bob Muller