OPAM 和 OCaml 安装

OPAM and OCaml installation

我在设置 OCaml 环境时遇到了一些问题,正在关注此页面:

https://github.com/realworldocaml/book/wiki/Installation-Instructions

但是,我遇到了一些无法解决的问题。我在 macOS 10.12.5 上使用 zsh。

Brew 安装 opam 时没有错误或警告。我相信我的问题是环境变量 (??) 不同步。以下是我 运行 一些建议命令时的一些输出:

opam 开关:

--     -- 4.04.2  Official 4.04.2 release
--     -- 4.05.0  Official 4.05.0 release
system  C system  System compiler (4.05.0)
# 251 more patched or experimental compilers, use '--all' to show

[WARNING] The environment is not in sync with the current switch.
          You should run: eval `opam config env`

求值'opam config env':

CAML_LD_LIBRARY_PATH="/Users/Alex/.opam/system/lib/stublibs:/usr/local/lib/ocaml/stublibs"; export CAML_LD_LIBRARY_PATH;
OPAMUTF8MSGS="1"; export OPAMUTF8MSGS;
MANPATH="/Users/Alex/.opam/system/man:"; export MANPATH;
PERL5LIB="/Users/Alex/.opam/system/lib/perl5"; export PERL5LIB;
OCAML_TOPLEVEL_PATH="/Users/Alex/.opam/system/lib/toplevel"; export OCAML_TOPLEVEL_PATH;
PATH="/Users/Alex/.opam/system/bin:/usr/local/opt/opencv3/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Wireshark.app/Contents/MacOS"; export PATH;

opam 安装基础:

The following actions will be performed:
  ∗  install sexplib v0.9.2                   [required by base]
  ∗  install base    v0.9.3
===== ∗  2 =====
Do you want to continue ? [Y/n] y

=-=- Gathering sources =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[base] Archive in cache
[sexplib] Archive in cache

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[ERROR] The compilation of sexplib failed at "jbuilder build -p sexplib -j 4".

#=== ERROR while installing sexplib.v0.9.2 ====================================#
# opam-version 1.2.2
# os           darwin
# command      jbuilder build -p sexplib -j 4
# path         /Users/Alex/.opam/system/build/sexplib.v0.9.2
# compiler     system (4.05.0)
# exit-code    127
# env-file     /Users/Alex/.opam/system/build/sexplib.v0.9.2/sexplib-35995-e7966f.env
# stdout-file  /Users/Alex/.opam/system/build/sexplib.v0.9.2/sexplib-35995-e7966f.out
# stderr-file  /Users/Alex/.opam/system/build/sexplib.v0.9.2/sexplib-35995-e7966f.err



=-=- Error report -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The following actions were aborted
  ∗  install base v0.9.3
The following actions failed
  ∗  install sexplib v0.9.2
No changes have been performed

出于问题的目的,我展示了我安装 base 的尝试,但最终我想安装 core、utop、oasis 等...非常感谢任何帮助!

编辑: 当我应该使用反引号 (`) 时,我使用了撇号 (')。我想 shell 用户没有经验的证据...

您在执行

时应该使用反引号(在许多键盘上位于 1 键的左侧)
eval `opam config env`

如果您找不到反引号,那么您可以使用替代的 shell 语法

eval $(opam config env)

注意:这个命令不应该打印任何东西,你看到环境变量值的事实表明你调用它是错误的(这个变量应该被 shell 看到)。