0f68c655326417111a5f4e25277a5bc0e8f59b9a
[lambda.git] / how_to_get_the_programming_languages_running_on_your_computer.mdwn
1 ## Notes ##
2
3 *   We were updating this page vigorously until about 2:30 pm on Saturday 31
4 January. Now it is relatively stable, but we'll tweak it as we learn more. We
5 encourage you to try to get the software set up sooner rather than later, and
6 those who do so first should let us know how things go---whether it's smoothly
7 or not---so that we might possibly refine or expand the instructions for
8 others. It'd be great if you took careful notes of what you did, step by step.
9 If our instructions are broken or misleading or incomplete, and you figure out
10 how to fix them on your own, it'd also be great if you can tell us what went
11 wrong and exactly what you did to achieve joy.
12
13 *   If you're using a Mac without the MacPorts package management system (on which
14 see below), then I think we can customize these directions so that everything
15 gets installed to your user directory, rather than to the system directories. This
16 reduces the chances of anything getting messed up, and makes it easier to remove
17 the software later. *Right now the instructions don't do this, but I'll be editing them
18 over the next hour or so to make them do it.*
19  
20  
21 ## Identifying your system ##
22
23 We'll assume you're using either Mac OS X, or Windows, or Linux.
24 If you're running **iOS**, you'll have a much harder time (perhaps impossible,
25 perhaps not) getting this software to run on your machine, and we can't give
26 you any guidance.
27
28 If you're using **Mac OS X**, take note of what version of the Mac OS you're
29 running. (Under the Apple Menu, select "About this Mac".)
30
31 *    Leopard (10.5)
32 *    Snow Leopard (10.6)
33 *    Lion (10.7)
34 *    Mountain Lion (10.8)
35 *    Mavericks (10.9)
36 *    Yosemite (10.10)
37
38 Furthermore, Mac users will be in one of two subgroups:
39
40 *   You'll have Apple's Xcode and the independent MacPorts system
41     installed. (Probably you don't. If you don't know what I'm talking about, you don't have these.)
42
43     If you don't have these, but want to try this route, you can read about
44     the MacPorts system at <http://www.macports.org/>.
45     This automates the building of Unix-type software on your Mac; it
46     makes it a lot easier to check for dependencies, use more-recent
47     versions of things, and so on. (Though as it happens, MacPorts only has an older version of
48     our chosen implementation of Scheme.)
49
50     There are also other package management systems available for the Mac, notably Homebrew and Fink. I only know a little bit about them.
51
52     There are instructions about how to get Xcode on the [Installing MacPorts](https://www.macports.org/install.php) page.
53     Some versions of [Xcode](http://developer.apple.com/xcode.html) are available for free on the Mac App Store.
54     Other versions are available through Apple's Developer website (some of these are free, but do require you to
55     register with Apple as an "Apple Developer", which involves clicking to accept a legal agreement with Apple).
56     I have an older version of this installed. If you download a recent version, email me and let me know how the
57     process works so I can tell others.
58     <!--
59     The latest version of Xcode to work with 10.5 / Leopard is 3.14; more recent versions (>= 3.2) require 10.6 / Snow Leopard.
60     3.2.6 is last version that can be downloaded for free by users of 10.6 / Snow Leopard. (But if they pay, they can use up to Xcode 4.2.)
61     Xcode 4.1 was free to all users of 10.7 / Lion. Is Xcode 4.6.x still available for free? Are Xcode 5.x and/or 6.x available for free?
62     -->
63
64 *   Or you won't have those installed. (**Most Mac users will be in this group.**)
65     Then you'll need pre-packaged (and usually pretty GUI) installers for
66     everything. These are great when they're available and kept up-to-date;
67     however sometimes those conditions aren't met.
68
69
70
71 If you're using **Windows**, you'll be in one of two subgroups:
72
73 *   You'll have the Cygwin system <http://www.cygwin.com/> installed.
74     This puts a Unix-like layer on top of your Windows system,
75     and makes it easier for you to use the same software everybody
76     else will be using, without its needing as much special-for-Windows
77     treatment. However, many of you won't have this installed.
78
79 *   You won't have Cygwin installed. (**Most Windows users will be in this group.**)
80     You might in theory have a different group of compilers installed
81     (MinGW, or Microsoft Visual C++) but we'll assume that the overwhelming
82     majority of users in this group don't have access to a compiler and
83     need pre-packaged installers for everything.
84
85
86 If you're using **Linux**, you could be using any one of numerous packaging
87 systems.
88
89 *   We'll give examples using the packaging system shared by Debian and Ubuntu,
90     and we'll assume that those of you using different packaging systems will know
91     how to make the relevant substitutions.
92
93
94 **For everyone**, a general item to take note of is what "processor architecture" your machine is running. Three of the possibilities are:
95
96 *   One of Intel's i386, i486, i586, i686 architectures. These are collectively known as "x86" or "IA-32" or sometimes just "32-bit".
97 *   Intel or AMD's x86\_64 architecture. This is also called "x64" or "amd64" or "IA-64" or sometimes just "64-bit". (Note that these *aren't* "x86" machines, even though "x86\_64" starts with those letters.)
98 *   ARM or some other architecture. These are generally lower-powered machines, like iPads. Some of the software we're proposing *might* in principle be capable of running on such machines, but installers don't seem to be available. We'll assume you have access to an x86 or x86\_64 machine.
99
100 On Linux or Mac OS X, you can open a terminal and type `uname -m`. If the
101 result is "x86\_64", then you've got x64/64-bit. If it's "i386" or something
102 like that, then you've got x86/32-bit. I think that Mac OS Xs from 10.7 / Lion
103 forward have all been x86\_64-only.
104
105 On Windows,
106 [here is a page that can help you figure this out](http://windows.microsoft.com/en-us/windows/32-bit-and-64-bit-windows).
107 I think that most machines running Windows XP will be x86/32-bit (unless it's
108 a version of Windows with "64-bit" or "x64" in its title); machines running
109 Windows Vista or Windows 7 or Windows 8 could be running either x86/32-bit or
110 x64/64-bit.
111
112
113 ## PLEASE REPORT PROBLEMS (AND SOLUTIONS!) ##
114
115 We haven't tested these instructions ourselves, and they're not explicit
116 step-by-step instructions in any case. If you encounter troubles, please email
117 to let us know so that we can amend the instructions to help others. If you
118 figure out how to fix the problem youself (and please do), please also write
119 with suggestions how we can change these instructions to make the process
120 easier and more straightforward for others.
121
122
123 ## Getting Scheme ##
124
125 **Scheme** is one of two or three major dialects of *Lisp*, which is a large family
126 of programming languages. The other dialects are called "Common Lisp" and "Clojure".
127 Scheme is the more clean and minimalist dialect, and is what's mostly used in
128 academic circles.
129
130 *   In your web browser:
131
132     There is a (slow, bare-bones) version of Scheme available for online use at <http://tryscheme.sourceforge.net/>.
133
134 Scheme itself has umpteen different "implementations", which share most of
135 their fundamentals, but have slightly different extensions and interact with
136 the operating system differently. One major implementation is called [Racket](http://racket-lang.org),
137 and that is what we recommend you use. (A few years back they were called PLT Scheme, but then
138 they changed their name to Racket.)
139 If you're already using or comfortable with
140 another Scheme implementation, though, there's no compelling reason to switch.
141
142
143 Another good Scheme implementation is [Chicken](http://www.call-cc.org). For our purposes, this is in some respects
144 superior to Racket, and in other respects inferior. If you have any issues with installing or using Racket, you could
145 try this out instead. You might even want to install both.
146
147 <!--
148 Racket doesn't have R7RS-small, and won't anytime soon.
149 Other R7RS-friendly: [Gauche](http://practical-scheme.net/gauche), [Chibi](https://code.google.com/p/chibi-scheme).
150 -->
151
152 Racket and Chicken stand to Scheme in something like the relation Firefox stands to HTML. They are two programs (or platforms) among others for working with the Scheme language; and many of those programs (or web browsers) permit different extensions, have small variations, and so on.
153
154 Racket has several components. The two most visible components for us are a command-line interpreter named "racket" and a teaching-friendly editor/front-end named "DrRacket". You will probably be working primarily or wholly in the latter.
155 <!-- "racket" used to be mzscheme, "DrRacket" used to be DrScheme -->
156
157 The current version of Racket is 6.1.1 (released November 2014).
158
159 *   **To install in Windows**
160
161     Go to <http://racket-lang.org/download/>. Download and install the "Windows x64" version. (Or the "Windows x86" verson if you have an older, 32-bit system.)
162
163 *   **To install on Mac without MacPorts**
164
165     Go to <http://racket-lang.org/download/>. Download and install the option for your system, most likely "Macintosh
166     OS X (Intel 64-bit)".
167
168     After you copy the files from the Installation disk to your /Applications folder, I think it's helpful to do these additional steps. In a Terminal, type:
169
170         sudo ln -s /Applications/Racket*/DrRacket.app /Applications/
171         sudo ln -s /Applications/Racket*/bin/racket /usr/bin/
172
173     Then you can launch Racket either by double-clicking the DrRacket icon in
174     your Applications folder (this gives you the GUI interface); or by typing
175     `racket` in a Terminal (this gives you the command-line version).
176
177 *   **To instead install Chicken Scheme on Mac without MacPorts**
178
179     Here are the exact steps I just verified worked. Note that I *first installed the Haskell Platform*, described further down this page; that installed some developer tools that were needed to build and install Chicken. If you don't know how to open a Terminal, move between directories, copy / rename / delete files and so on, then you're probably best off not doing this. You could break something.
180
181     1. Go to <http://code.call-cc.org>, and click the "Source code" link near the top. Current version is 4.9.0.1, released November 2014. This should fetch a file to your download folder, and will probably automatically unpack that file into a folder, "chicken-4.9.0.1". Click on that folder and press command-C / Copy, then open a Terminal.
182     2. In the terminal type `cd` followed by a space, then press command-V / Paste. Then press enter. This will move your session into the folder you just downloaded.
183     3. Type `less README` and read that file.
184     4. Type `sudo mkdir -p /usr/local`
185     5. Type `make PLATFORM=macosx XCODE_DEVELOPER= XCODE_TOOL_PATH=/usr/bin`
186
187     The options starting with `XCODE_` are to tell the Chicken build scripts that I've got the developer tools installed in my main system, rather than as part of Xcode. (That's where the Haskell Platform installer put them.) Continuing:
188
189     6. Wait a while while Chicken builds.
190     7. If it finishes with no errors, then type `sudo make PLATFORM=macosx XCODE_TOOL_PATH=/usr/bin install`. This will prompt you for your account password, and then install Chicken underneath your `/usr/local` directory.
191     8. At this point you can type `which chicken`. If it gives you an answer of "/usr/local/bin/chicken", then skip to the next step. Else you should type `echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bashrc`, then exit and restart your Terminal session.
192     9. In your terminal, type `chicken-install -sudo r7rs datatype matchable monad`. This will download, build, and install a few extensions (Chicken calls them "eggs") relevant to ideas we'll be working with in this course.
193
194 *   **To install on Mac with MacPorts**
195
196     Unfortunately, MacPorts doesn't have Racket itself available. It only has an older version from when they still called
197     themselves PLT Scheme. And even then, it only has the command-line program "mzscheme" (what's nowadays called "racket"); it
198     doesn't have the GUI program that corresponds to what's now called "DrRacket". You can install mzscheme by opening a Terminal
199     window and typing:
200
201          sudo port install mzscheme
202
203     <!-- mzscheme v4.1.5, from March 2009; latest mzscheme is 4.2.5, from April 2010 -->
204
205     If you want the GUI components, I think you'll need to use the
206     "Mac/without MacPorts" installation options above. Or you could try the Chicken Scheme implementation instead of Racket. This is more current.
207     To do that, type:
208
209         sudo port install chicken readline
210
211     <!-- chicken v4.8.0.2, from Feb 2013; latest available is 4.9.0.1, from Nov 2014 -->
212
213     Whether you use mzscheme or Chicken, I recommend also typing:
214
215         sudo port install rlwrap
216
217     then if you ever use the command-line program `mzscheme` (or `racket`, for that matter), you should start it by typing `rlwrap mzscheme` (or whatever). This gives
218     you a nice history of the commands you've already typed, which you can scroll up and down in with your
219     keyboard arrows.
220
221 *   **To install on Linux**
222
223     Use your packaging system, for example, open a Terminal and
224     type:
225
226          sudo apt-get install racket
227
228     It's very likely that your packaging system has some version of
229     Racket available, so look for it. However, if you can't find it you
230     can also install a pre-packaged binary from the Racket website at <http://racket-lang.org/download/>.
231     Choose the option for your version of Linux (Ubuntu and Debian are available).
232
233     As above, I recommend you also type:
234
235         sudo apt-get rlwrap
236
237     then if you ever use the command-line program `mzscheme` (or `racket`), you should start it by typing `rlwrap mzscheme` (or whatever). This gives
238     you a nice history of the commands you've already typed, which you can scroll up and down in with your
239     keyboard arrows.
240
241
242 ## Getting OCaml ##
243
244 **Caml** is one of two major dialects of *ML*, which is another large family of
245 programming languages. The other dialect is called "SML" and has several
246 implementations. But Caml has only one active implementation, OCaml or
247 Objective Caml, developed by the INRIA academic group in France.
248 Sometimes we may refer to Caml or ML
249 more generally; but you can assume that what we're talking about always works more
250 specifically in OCaml.
251
252 It's helpful if in addition to OCaml you also install the
253 Findlib add-on and/or the [OPAM](https://opam.ocaml.org) "package manager."
254 These will make it easier to install additional add-ons further down the road.
255 However, if you're not able to get them working, don't worry about it much.
256
257 The current version of OCaml is 4.02.1 (released October 2014).
258 <!-- 3.12.1 July 2011; 4.00.1 Oct 2012; 4.01.0 Sept 2013; 4.02.0 Aug 2014; 4.02.1 Oct 2014 -->
259
260
261 *   In your web browser:
262
263     There is a (slow, bare-bones) version of OCaml available for online use at <http://try.ocamlpro.com/>.
264
265
266 *   **To install in Windows**
267
268     There are *five* different strategies for installing OCaml on Windows. I don't know which works best.
269
270     1.  First, you can go to <http://caml.inria.fr/download.en.html>.
271     You can probably download and install the
272     "Self installer for the port based on the MinGW toolchain"
273     even if you don't know what MinGW or Cygwin are.
274     Some features of this require Cygwin, but it looks like
275     it should mostly work even for users without Cygwin.
276     At the time of this writing, only an installer for an earlier
277     version of OCaml (4.01.0, from September 2013) is available.
278
279     2.  A second strategy uses a package called
280         [OCPWIN](http://ocaml.org/docs/install.html#OCPWINSelfContainedOCamlforWindows). This also installs only version 4.01.0.
281
282     3.  The [three remaining strategies](http://ocaml.org/docs/install.html#OCamlonCygwin) in some way
283     use the Cygwin environment, mentioned earlier on this page. At least one of
284     those three methods will automatically fetch and help you install Cygwin.
285     The first method listed on that page says it installs version 4.00.1, but
286     really it's been updated and now installs the (somewhat newer, but still
287     not the newest) version 4.01.0.
288
289     Some of these methods may automatically install Findlib for you. If not,
290     you can try installing it yourself but I think you'll need the Cygwin
291     system installed to do so. I'm not going to explain how to do this.
292     If you want to figure it out yourself, go to the
293     Findlib website at <http://projects.camlcity.org/projects/findlib.html>.
294
295 *   **To install on Mac without MacPorts**
296
297     The people in charge of OCaml (they're at the French research institute INRIA) have stopped making pre-built packages for Mac OS X. One option you have is to use their package for a slightly older version of OCaml, 4.01.1 from Sept. 2013. You can find that as a "Precompiled binary for Mac OS X" on [this page](http://ocaml.org/releases/4.01.0.html). If, when you attempt to install this package, you get an error about its being from an "unidentified developer," you need to control-click on the `ocaml.pkg` file and select "Open", then when the warning box appears again, this time there will be an "Open" button that you can click. Then you can continue running the Installer.
298
299     A second option is to install the OPAM package manager and use that to build and install the latest version of OCaml. Here's how to do that:
300
301     1.  Download [this file](https://raw.github.com/ocaml/opam/master/shell/opam_installer.sh) and
302     note where it gets saved to. If it opens in your browser, then type
303     command-S / Save Page and save it somewhere on your disk, again noting its
304     location.
305
306     2.  Open a terminal and type:
307         
308             sudo mkdir -p /usr/local/bin
309             sudo sh /path/to/opam_installer.sh /usr/local/bin
310
311         Except replace `/path/to` with the real location, that you noted in step 1.
312
313     3.  If that works, then type:
314
315             opan init --comp 4.01.0
316
317         or whatever it was that the OPAM installer prompted you to type. This will download and install a fresh version of OCaml, and will take a bit of time.
318
319 <!--
320 If you do have Xcode, and want to do without MacPorts, then
321 what you need to do is download Findlib from
322 <http://download.camlcity.org/download/findlib-1.2.6.tar.gz>.
323 Unpack the download, open a Terminal and go into the folder you just
324 unpacked, and type:
325
326     ./configure
327     make package-macosx
328
329 This will build an installer package which you should be able to
330 double-click and install.
331 -->
332
333 *   **To install on Mac with MacPorts**
334
335     You can install the current version of OCaml (4.02.1, from October 2014),
336     together with the Findlib add-on and OPAM package manager, by opening a Terminal and typing:
337
338         sudo port install ocaml ocaml-findlib opam
339
340     As with Scheme, it's helpful to also have rlwrap installed, and to start OCaml as `rlwrap ocaml`. This gives
341     you a nice history of the commands you've already typed, which you can scroll up and down in with your
342     keyboard arrows.
343
344 *   **To install on Linux**
345
346     Use your packaging system, for example, open a Terminal and
347     type:
348
349         sudo apt-get install ocaml opam camlp4-extra ocaml-findlib
350
351     That will install a version of OCaml and the Findlib add-on and OPAM package manager.
352
353     If you're using Ubuntu "Utopic" (14.10), there's [a note on the OPAM home page](https://opam.ocaml.org/doc/Install.html)
354     warning that its version of OPAM is broken, and not to use it. Here's how you can get (OCaml and) OPAM from a newer repository:
355
356         sudo apt-get install -y software-properties-common
357         sudo apt-apt-repository -y ppa:avsm/ppa
358         sudo apt-get update
359         sudo apt-get install ocaml opam
360
361     If for some reason you can't get OCaml through your Linux packaging system, you can go to
362     <http://caml.inria.fr/download.en.html>.
363     Pre-packaged binary installers are available for several Linux systems.
364
365     If you can't get findlib through your packaging system, you'll need to download it from
366     <http://download.camlcity.org/download/findlib-1.5.5.tar.gz>.
367     and use gcc to compile it yourself. If you don't know how to do that, you probably don't want to attempt this.
368     Here are the INSTALL notes:
369     <https://godirepo.camlcity.org/svn/lib-findlib/trunk/INSTALL>.
370
371     As with Scheme, it's helpful to also have rlwrap installed, and to start OCaml as `rlwrap ocaml`. This gives
372     you a nice history of the commands you've already typed, which you can scroll up and down in with your
373     keyboard arrows.
374
375
376
377 ## Getting Haskell ##
378
379 This last installation is less crucial than the others, since we will be focusing
380 primarily on Scheme and OCaml. However we, and the readings you come across,
381 will sometimes mention Haskell, so it might be worth your installing this too,
382 so that you have it available to play around with.
383
384 Haskell is used a lot in the academic contexts we'll be working through. At one point, Scheme
385 dominated these discussions but now Haskell seems to do that.
386
387 Haskell's surface syntax differs from Caml, and there are various important things one can do in
388 each of Haskell and Caml that one can't (or can't as easily) do in the
389 other. But these languages also have *a lot* in common, and if you're
390 familiar with one of them, it's generally not hard to move between it and the
391 other.
392
393 *   In your web browser:
394
395     There is a (slow, bare-bones) version of Haskell available for online use at <http://tryhaskell.org/>.
396
397 Like Scheme, Haskell has a couple of different implementations. The dominant one, and the one we recommend you install, is called [GHC](https://wiki.haskell.org/GHC), short for "Glasgow Haskell Compiler". To install this on your machine, there are a couple of different strategies. It's helpful to understand some lingo as you begin this process:
398
399 *   As mentioned, **GHC** is the main Haskell engine or compiler you'll be installing. The current version is 7.8.4, from December 2014.
400 *   **gcc** and **llvm/clang** and **Xcode** and **MinGW** are names for other compilers on various systems. Oftentimes these will be used during the installation process to get GHC up and running. Some of the strategies described below will help you install these if they're not already on your machine.
401 *   **alex** and **happy** and **haddock** are names of various Haskell helper programs that GHC uses to get up and running.
402 *   **[Cabal](https://www.haskell.org/cabal)** is a "package manager" for Haskell. It allows you to install libraries or extensions that other people have built. (Usually those are published at the [Hackage](https://hackage.haskell.org) web site.) Some of these are experimental and may not always work; others are quite fundamental and are almost de facto parts of what people expect in a Haskell system.
403 *   **[Haskell Platform](https://www.haskell.org/platform)** is a standard bundle that includes a fixed version of GHC, plus fixed versions of some of the most popular libraries or extensions. This is updated once or twice a year. The current version is 2014.2.0.0, from August 2014. It includes GHC version 7.8.3.
404
405 The easiest way to get up and running with Haskell/GHC is to install the Haskell Platform. Here's how to do that **on Windows**:
406
407 *   Go to <https://www.haskell.org/platform/windows.html> and follow the instructions. It looks like this process will automatically install the MinGW compiler needed to get this build of Haskell running on Windows.
408
409 On **Mac without MacPorts**:
410
411 *   Go to <https://www.haskell.org/platform/mac.html> and follow the instructions. This requires Mac OS X 10.6 / Snow Leopard or later; but there is a link to an earlier version of Haskell Platform, that's built for Mac OS X 10.5 / Leopard. During the installation, you may be prompted to install "the command line developer tools"; this is a portion of what Apple bundles together with Xcode (mentioned above on this page). The installer will take care of getting these for you if you give it permission.
412
413 On **Mac with MacPorts**:
414
415 *   In a Terminal, type `sudo port install haskell-platform`.
416
417 On **Ubuntu or Debian Linux**:
418
419 *   In a Terminal, type `sudo apt-get install haskell-platform`.
420
421
422 It's useful to know about the general [Haskell wiki](https://wiki.haskell.org) (not restricted to just GHC). They have a [Getting Started](https://wiki.haskell.org/Haskell_in_5_steps) page, which also recommends that you install the Haskell Platform.
423
424 If any of the instructions above don't work, then you can try alternative instructions for [Mac](http://new-www.haskell.org/downloads/osx) or [Windows](http://new-www.haskell.org/downloads/windows) or [Ubuntu](http://new-www.haskell.org/downloads/linux). Note that this method doesn't install all the extensions that are part of the Haskell Platform, but only the core pieces of GHC. You can use Cabal to download and manage any extra extensions you turn out to need, down the road.
425
426 **After installing Haskell**, open a Terminal and type:
427
428     cabal update
429
430 It may give you a message about updating your `PATH` variable. On my Mac, I first typed `echo $PATH` and verified that `/usr/local/bin` appeared somewhere in the resulting string. (The elements are divided by `:` characters.) Then I typed this:
431
432     echo 'export PATH="$HOME/Library/Haskell/bin:$PATH"' >> ~/.bash_profile
433
434 That was to update my `PATH` variable as instructed by Cabal. On a Linux machine, or if you installed Haskell differently on your Mac, you might have to type instead:
435
436     echo 'export PATH="$HOME/.cabal/bin:$PATH"' >> ~/.bash_profile
437
438 Some instructions may say to use `.bashrc` instead of `.bash_profile`. These files do similar jobs.
439
440 After issuing the relevant `echo` command, I exited the Terminal and started a new Terminal session. Now if I type `echo $PATH` I should see the directory I just added in the list. Now I can contine setting up Cabal. I type:
441
442     which alex happy
443
444 If that gives me back two pathnames, one to the program `alex` and the other to the program `happy`, then I'm already finished. If not, then I type:
445
446     cabal install alex happy
447
448 This installs those two programs. They are helpers that Cabal needs to build and install some packages.
449
450 <!-- https://github.com/pittsburgh-haskell/haskell-installation -->
451