Psellos
Life So Short, the Craft So Long to Learn

Install OCaml on Amazon Linux (EC2)

June 19, 2012

Edited September 2, 2012

Here is a quick way to get OCaml installed on an Amazon EC2 instance running Amazon Linux. The problem is that you’d like to use yum, the handy package management tool. But none of the stock repositories in Amazon Linux contains an OCaml package.

Powered by OCaml

Since Amazon Linux is compatible with CentOS 6, what I ended up doing was installing the OCaml package from CentOS 6.2. This gives you OCaml 3.11.2, which is perfectly fine for our current purposes. We’ve run a few tests, and it is working for us.

Note: if you’re not committed to using Amazon Linux, another way to get OCaml support is to use the Ubuntu images instead. I’ve run some tests with the 32-bit version of Ubuntu Server 12.04 LTS, and the OCaml support seems excellent. The repository contains OCaml 3.12.1, which is the latest release (currently).

For those who want to use OCaml on Amazon Linux, here are the steps I used to install it. I assume you’ve got an active EC2 instance running Amazon Linux.

First, add the CentOS 6.2 repository to your yum configuration. As root, create a file named /etc/yum.repos.d/centos6.repo with the following contents. The mirrorlist and gpgkey lines here might be wrapped in your browser, but each is one long line (make your browser as wide as possible to see this).

[centos6]
name=Centos 6 Base
mirrorlist=http://mirrorlist.centos.org/?release=6.2&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos-6/6/os/$basearch/RPM-GPG-KEY-CentOS-6
priority=2
enabled=1

(Added note: based on a comment, I changed the gpgkey URL above. The old URL had become inaccessible since I originally wrote this up. To check the validity, you can try visiting the URL to make sure it exists. Replace $basearch with i386 or x86_64 as appropriate.)

To avoid overriding the stock packages you want to set the priority lower than the other repositories (i.e., set it to a bigger integer). All my other repositories are priority 1, so 2 is big enough.

The use of the basearch variable means that things will work for both 32- and 64-bit EC2 instances. The lines below are taken from a 32-bit instance (but I have tested on both).

Yum should now see the CentOS OCaml package:

# yum list ocaml
Loaded plugins: fastestmirror, priorities, security, update-motd
Loading mirror speeds from cached hostfile
* amzn-main: packages.us-west-2.amazonaws.com
* amzn-updates: packages.us-west-2.amazonaws.com
* centos6: mirrors.cat.pdx.edu
2125 packages excluded due to repository priority protections
Available Packages
ocaml.i686                   3.11.2-2.el6                   centos6

You can now install OCaml:

# yum install ocaml
    . . .
# ocaml
        Objective Caml version 3.11.2
 
#

When you’re done, you might want to change enable=1 to enable=0 in your centos6.repo file, to avoid placing unnecessary load on the CentOS mirrors in the future.

Please leave any corrections, questions, or comments below, or send them to me at jeffsco@psellos.com.

Posted by: Jeffrey

Comments

blog comments powered by Disqus