update week1 notes
[lambda.git] / how_to_get_the_programming_languages_running_on_your_computer.mdwn
index 0f68c65..dcd8d1f 100644 (file)
@@ -10,12 +10,17 @@ If our instructions are broken or misleading or incomplete, and you figure out
 how to fix them on your own, it'd also be great if you can tell us what went
 wrong and exactly what you did to achieve joy.
 
-*   If you're using a Mac without the MacPorts package management system (on which
-see below), then I think we can customize these directions so that everything
-gets installed to your user directory, rather than to the system directories. This
-reduces the chances of anything getting messed up, and makes it easier to remove
-the software later. *Right now the instructions don't do this, but I'll be editing them
-over the next hour or so to make them do it.*
+*   On a Mac or Linux system, you have a number of *system directories* such as `/usr` and `/Library`,
+    and also your *user home directory* which will be named something like `/User/george` or `/home/george`
+    if you are `george`. Other ways to refer to the user home directory are as `~` (the tilde character)
+    or as `$HOME`. When installing software, you sometimes have a choice of whether to install it into
+    the system directories or in subdirectories of your user home. When this choice was available,
+    I made the instructions that follow select the latter. This makes it somewhat harder for things
+    to get messed up, and makes it somewhat easier for you to remove things later.
+
+    If you're using a Mac without MacPorts (explained below), then Chicken and
+    OCaml will be installed under your user home; but Racket's and GHC's
+    Installers put them into system directories.
  
  
 ## Identifying your system ##
@@ -120,6 +125,16 @@ with suggestions how we can change these instructions to make the process
 easier and more straightforward for others.
 
 
+## Preliminaries ##
+
+If you're using Linux or a Mac without MacPorts, then open a Terminal and type the following. You probably want to copy and paste it to make sure you don't make mistakes:
+
+    (IFS=:; for p in $PATH; do [ /usr/local/bin = "$p" ] && exit 0; done;
+            echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile)
+    mkdir -p ~/bin
+    echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bash_profile
+
+
 ## Getting Scheme ##
 
 **Scheme** is one of two or three major dialects of *Lisp*, which is a large family
@@ -168,28 +183,30 @@ The current version of Racket is 6.1.1 (released November 2014).
     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:
 
         sudo ln -s /Applications/Racket*/DrRacket.app /Applications/
-        sudo ln -s /Applications/Racket*/bin/racket /usr/bin/
+        ln -s /Applications/Racket*/bin/racket ~/bin/
+
+    (If you get an error about ".../bin/: No such file or directory", then you didn't follow the Preliminary instructions above.)
 
     Then you can launch Racket either by double-clicking the DrRacket icon in
     your Applications folder (this gives you the GUI interface); or by typing
     `racket` in a Terminal (this gives you the command-line version).
 
+    Instead of, or in addition to, the first line above, you could drag the *DrRacket.app* icon to your Dock.
+
 *   **To instead install Chicken Scheme on Mac without MacPorts**
 
     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.
 
     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.
-    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.
-    3. Type `less README` and read that file.
-    4. Type `sudo mkdir -p /usr/local`
-    5. Type `make PLATFORM=macosx XCODE_DEVELOPER= XCODE_TOOL_PATH=/usr/bin`
+    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.  <!-- Type `less README` and read that file. -->
+    3. Type `make PLATFORM=macosx XCODE_DEVELOPER= XCODE_TOOL_PATH=/usr/bin PREFIX=$HOME` <!-- PREFIX defaults to /usr/local -->
 
     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:
 
-    6. Wait a while while Chicken builds.
-    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.
-    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.
-    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.
+    4. Wait a while while Chicken builds.
+    5. If it finishes with no errors, then type `make PLATFORM=macosx XCODE_TOOL_PATH=/usr/bin PREFIX=$HOME install`. This will install Chicken in your user home directory.
+    6. At this point you can type `which chicken`. It should give you an answer of "/Users/yourname/bin/chicken".
+    7. In your terminal, type `chicken-install r7rs datatype matchable monad`. <!-- with "-sudo" if you installed chicken in /usr/local --> This will download, build, and install a few extensions (Chicken calls them "eggs") relevant to ideas we'll be working with in this course.
 
 *   **To install on Mac with MacPorts**
 
@@ -305,17 +322,18 @@ The current version of OCaml is 4.02.1 (released October 2014).
 
     2.  Open a terminal and type:
         
-            sudo mkdir -p /usr/local/bin
-            sudo sh /path/to/opam_installer.sh /usr/local/bin
+            sh /path/to/opam_installer.sh ~/bin
 
-        Except replace `/path/to` with the real location, that you noted in step 1.
+        Except replace `/path/to` with the real location, that you noted in step 1. When prompted "Do you want OPAM to modify ~/.bash_profile and ~/.ocamlinit?", say "y".
 
     3.  If that works, then type:
 
-            opan init --comp 4.01.0
+            opam init --comp 4.01.0
 
         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.
 
+<!-- To upgrade: opam switch 4.02.1 && eval `opam config env` -->
+
 <!--
 If you do have Xcode, and want to do without MacPorts, then
 what you need to do is download Findlib from
@@ -354,7 +372,7 @@ double-click and install.
     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:
 
         sudo apt-get install -y software-properties-common
-        sudo apt-apt-repository -y ppa:avsm/ppa
+        sudo add-apt-repository -y ppa:avsm/ppa
         sudo apt-get update
         sudo apt-get install ocaml opam
 
@@ -400,7 +418,7 @@ Like Scheme, Haskell has a couple of different implementations. The dominant one
 *   **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.
 *   **alex** and **happy** and **haddock** are names of various Haskell helper programs that GHC uses to get up and running.
 *   **[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.
-*   **[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.
+*   **[Haskell Platform](https://www.haskell.org/platform)** is a standard bundle that includes a specific version of GHC, plus specific 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.
 
 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**:
 
@@ -410,6 +428,31 @@ On **Mac without MacPorts**:
 
 *   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.
 
+<!--
+The Installer places everything in your system directories. If you'd like it instead in your user directory (easier to clean up later), you can do this after running the Installer:
+
+    mkdir ~/Library/Frameworks
+    cp -a /Library/Frameworks/GHC.framework ~/Library/Frameworks/
+    [ -d ~/Library/Haskell ] && mv ~/Library/Haskell ~/Library/Haskell.orig
+    sudo mv /Library/Haskell ~/Library/
+    sudo chown -Rh $USER:staff ~/Library/Haskell
+    mkdir -p ~/share/doc ~/share/man/man1
+    ln -s ~/Library/Frameworks/GHC.framework/Versions/Current/usr/share/doc/ghc ~/share/doc/
+    ln -s ~/Library/Frameworks/GHC.framework/Versions/Current/usr/share/man/man1/ghc.1 ~/share/man/man1/
+    sudo rm -r /usr/share/doc/ghc /usr/share/man/man1/ghc.1 /Library/Frameworks/GHC.framework
+    for f in ghc ghc-7.8.3 ghc-pkg ghc-pkg-7.8.3 ghci ghci-7.8.3 haddock haddock-ghc-7.8.3 hp2ps hpc hsc2hs runghc runghc-7.8.3 runhaskell; do
+      ln -s ~/Library/Frameworks/GHC.framework/Versions/7.8.3-*/usr/bin/$f ~/bin/
+      sudo rm /usr/bin/$f
+    done
+    for f in activate-hs alex cabal cabal.real cabal.wrap ghc-clang-wrapper happy HsColour uninstall-hs; do
+      ln -s /Library/Haskell/ghc-7.8.3-*/bin/$f ~/bin/
+      sudo rm /usr/bin/$f
+    done
+    sed -i "" "s=/Library=$HOME/Library=g" $(fgrep -RIl /Library ~/Library/Haskell ~/Library/Frameworks/GHC.framework | fgrep -v .html)
+
+# Ehh. Doesn't work...
+-->
+
 On **Mac with MacPorts**:
 
 *   In a Terminal, type `sudo port install haskell-platform`.
@@ -427,11 +470,11 @@ If any of the instructions above don't work, then you can try alternative instru
 
     cabal update
 
-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:
+It may give you a message about updating your `PATH` variable. On my Mac, I was prompted to do this:
 
     echo 'export PATH="$HOME/Library/Haskell/bin:$PATH"' >> ~/.bash_profile
 
-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:
+On a Linux machine, or if you installed Haskell differently on your Mac, you might have to type instead:
 
     echo 'export PATH="$HOME/.cabal/bin:$PATH"' >> ~/.bash_profile