The aim of this video is to introduce how to install Haskell on Linux.
- [Hakim] In this video, we're going to install Haskell onto a Linux machine, specifically, Ubuntu Linux. Now here I've prepared an Ubuntu machine running the latest LTS, long-term support, release 16.04. So I'm going to go to Haskell.org and click on the downloads link right at the top of the page. And as we discussed, we're going to install Stack in order to get hold of the Haskell tool chain.
So if I click on that, and we can see in this how to get it section that there are links for various different platforms. Now, because I've got Ubuntu Linux, I'm going to go ahead and click on this link. If however you are using a different distro, then I recommend going to the install and upgrade page and following the instructions there. Now for the common case of Ubuntu, I'm simply going to click on the link here, and as you can see, we are going to just install a package using APT, the Debian and Ubuntu package manager, but because we're getting the package from a different repository rather than the usual Ubuntu repositories, we first of all need to get a key from FP Complete which is the company that manages this repository.
So I'm going to copy that line, and go to my terminal and run that command. This is simply going to download a key to make sure that we have encrypted access to their repository and install the correct package safely. As you can see here, we've imported a public key for FPComplete.com. As I mentioned, I am running Ubuntu 16.04, however, if you're at all uncertain which version of Ubuntu you are running, you can simply type this command here, lsb_release -a, so let's just try that here, and we can confirm that we are indeed running Ubuntu 16.04.
So that means I need to run this command here which will simply copy this line, deb http://download.fpcomplete.com et cetera, et cetera, to my sources list for APT. Okay. And then the final command we need to run for the installation part is to update our repositories and install the package Stack.
So I'm going to go ahead and paste that. Now this can take longer or a shorter time depending on which packages you've already got installed. So as you can see here, it's setting up Stack, and that was quite quick. So, all we need to do now is to actually configure Stack for use, so, let's run Stack setup.
And you can see here it's talking about implicit global project config, and that's because I haven't set up a config file for a particular project. I'm just installing GHC globally to this machine. Now this may take some time. It's installing GHC 8.0.1.
That version will depend on whatever the latest stable release is at the time that you run it because we didn't specify a specific version of GHC. So as you can see, Stack gives you some information about how to invoke the Glasgow Haskell Compiler running, for example, Stack GHC or Stack GHCI, and so on. Just a quick side note here, you do want to type Stack GHCI rather than GHCI.
Even though Ubuntu will helpfully tell you about the system package, we want to make sure that we're using a recent, up-to-date package that we've installed using Stack. So instead, what we need to run is actually Stack GHCI, and as you can see, this then uses version 8.0.1 which it downloaded above, and we can now run some simple expressions in the interpreter.
And that's the end of the section on installing Haskell. In the next section, we're going to look at getting started with Haskell, and we'll continue to experiment with GHCI, which is the interactive interpreter.
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Discovering Haskell with GHCI
- Haskell datatypes and functions
- Using higher order functions for data manipulation and code reuse
- Editing Haskell source code
- Creating a project with Stack
- Writing and conducting tests