Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the most recent version of Cabal for Haskell?

Tags:

haskell

cabal

I've just spent about an hour going in circles trying to get version 2 of Cabal. Initially I found that the version that came with my LinuxMint install was version 1, so I tried cabal update, didn't do it. So I found instructions which said to use cabal install Cabal cabal-install. Did it, got an error. Found that the error apparently had to do with using the most current version of Haskell. So I installed version 7 to get Cabal. Seemed to work, looked like I finally got Cabal version 2. But I also want the most current version of Haskell so I downloaded the binaries for it and installed that again--now it seems like Cabal is set back to version 1. Is it not possible to have both version 8 of Haskell and version 2 of Cabal?

like image 570
Addem Avatar asked Mar 06 '23 03:03

Addem


1 Answers

Along the lines of danidiaz's comments, I suggest directly installing cabal-install in your home directory.

Begin by making sure you are actually using the 8.x version of GHC you want (use which ghc and ghc --version if need be). Also, get rid of any other cabal-install versions you might have installed, so that there is less margin for confusion.

The [directory] ~/.cabal/bin is not in my PATH variable, should I put it in toward the front of its definition?

Exactly. ~/.cabal/bin is the default location for executables locally installed with cabal-install, which includes cabal-install itself, and so it must be in the PATH. Putting it towards the front of the PATH will give it priority over any system-wide installation of cabal-install installed with your package managers. (Note that that won't be an issue if you remove said system-wide installation beforehand.)


Once the terrain is clear, you can download a suitable binary tarball from Cabal's download page, extract the executable and put it in ~/.cabal/bin. As danidiaz notes, the binaries there aren't necessarily at the latest stable version (as I write this, the Linux binaries are 2.2.0.0 rather than 2.4.0.0), but that likely won't matter, as once you have some version of cabal-install available you can simply run...

cabal new-update # For version 2.4 or above; if not, use cabal update instead.
cabal new-install cabal-install

... which will update your cabal-install to the latest stable version.

(Note that I'm using the new-* cabal-install commands. I strongly advise you to do the same.)


Also, looking through the Cabal folder, I don't see binaries. The only folders present are Distribution, Language, tests, and doc.

It sounds like you downloaded the sources of Cabal, the library, rather than the ones of cabal-install, the tool. The cabal-install sources are also available from the download page linked above (as I write this, their version is 2.4.0.0). If you are getting them from GitHub instead, you should look into the cabal-install directory, rather than the Cabal one. Either way, once yo are in the appropriate directory, to install from source run...

./bootstrap.sh --sandbox

... which only requires GHC (as opposed to a pre-existing cabal-install). Once it finishes building cabal-install, the script will tell you the location of the executable (presumably in a .cabal-sandbox/bin subdirectory). Copy the executable to ~/.cabal/bin and proceed as before.

like image 100
duplode Avatar answered Mar 15 '23 05:03

duplode