简体   繁体   English

在Mac OS X上安装OCaml

[英]Installation of OCaml on Mac OS X

How to install OCaml 4.02.3 ( https://ocaml.org/releases/4.02.html ) on Mac OS X Yosemite? 如何在Mac OS X Yosemite上安装OCaml 4.02.3( https://ocaml.org/releases/4.02.html )? Is it a must to install it with terminal? 用终端安装它是必须的吗? If so, what are steps for it? 如果是这样,它的步骤是什么? I am a newbie to OS X, and it is highly appreciated if any solutions are provided. 我是OS X的新手,如果提供任何解决方案,我们非常感谢。 Thanks a lot! 非常感谢!

I recommend using opam , which is the most up to date packaging system for OCaml. 我推荐使用opam ,这是OCaml最新的包装系统。 Not only can you get the compiler, but also essentially all useful OCaml libraries. 您不仅可以获得编译器,还可以获得基本上所有有用的OCaml库。 The only issue is that opam is implemented in OCaml, so you have to install OCaml to install opam. 唯一的问题是opam是在OCaml中实现的,因此您必须安装OCaml才能安装opam。 There are a couple of solutions. 有几种解决方案。

  1. First, an opam homebrew package is maintained, so if you use homebrew, you can simply do brew install opam . 首先,维护一个opam homebrew包,所以如果你使用自制软件,你可以简单地做brew install opam If you do this, note you'll also end up with OCaml installed as a homebrew package. 如果你这样做,请注意你最终将安装OCaml作为自制程序包。 If you don't want any other libraries, you're done and can start using OCaml. 如果您不想要任何其他库,那么您已经完成并可以开始使用OCaml。 However, below I'm going to tell you to again install OCaml via opam, so you'll end up with two installations, which isn't a problem. 但是,下面我将告诉你再次通过opam安装OCaml,所以你最终会安装两个,这不是问题。 The difference is with the opam installation, you can additionally start installing more OCaml libraries, which are not available in homebrew. 不同之处在于opam安装,您可以另外开始安装更多的OCaml库,这些库在自制软件中是不可用的。

  2. You can avoid the double installation of OCaml by using the precompiled binaries of opam that are available on its releases page. 您可以通过使用其发布页面上提供的预编译的opam二进制文件来避免OCaml的双重安装。 Just download the binary for Darwin to a location of your choice. 只需将Darwin的二进制文件下载到您选择的位置即可。

Once you have opam installed, you can do opam init , and this will install the latest version of OCaml. 一旦安装了opam,就可以执行opam init ,这将安装最新版本的OCaml。 You can then do opam list to see all the libraries available, and install one of them, eg opam install core to get the library used in Real World OCaml. 然后,您可以执行opam list以查看所有可用库,并安装其中一个库,例如opam install core以获取Real World OCaml中使用的库。 Opam installs everything under ~/.opam , so just delete that whole directory to undo everything. Opam安装~/.opam下的所有内容,所以只需删除整个目录即可撤消所有内容。 (Almost everything, it does also modify your login file a bit. I use the -n option to opam init because I don't like my files getting automatically modified, and I know what to do myself.) (几乎所有东西,它也会修改你的登录文件。我使用-n选项来opam init因为我不喜欢我的文件被自动修改,我知道自己该做什么。)

Is it a must to install it with terminal? 用终端安装它是必须的吗?

Yes. 是。

安装Macport并从终端运行:

$ sudo port install ocaml opam

I don't successfully install the MacPorts, So I install the Brew. 我没有成功安装MacPorts,所以我安装了Brew。 https://brew.sh/ and then you can input: brew install opam https://brew.sh/然后你可以输入:brew install opam

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM