Difference between revisions of "Cabal/How to install a Cabal package"

From HaskellWiki
Jump to: navigation, search
(only the manual installation section is outdated)
(Remove outdated stuff)
 
Line 1: Line 1:
 
[[Category:How to]]
 
[[Category:How to]]
   
There's an interesting Haskell package on [http://hackage.haskell.org/packages/archive/pkg-list.html Hackage] you'd like to try. How do you install it on your system?
+
There's an interesting Haskell package on [http://hackage.haskell.org/ Hackage] you'd like to try. How do you install it on your system?
   
== Installing packages using cabal ==
+
== Installing a library ==
By far the easiest way is to use the <code>cabal</code> command line tool to install a new package and its dependencies. The command is provided by a package called cabal-install. It can be installed using [https://haskell.org/ghcup ghcup], and <code>cabal</code> is also part of the [http://haskell.org/platform Haskell Platform], other methods are listed at [[Distributions]]. The [[Cabal-Install]] page explains how to use <code>cabal</code>.
 
   
  +
While it is possible to "install" a library package "globally" it is most certainly a [https://en.wikipedia.org/wiki/Dependency_hell bad idea].
   
If you so wish, you can still install packages manually -- see the section below.
 
  +
You should use project environment and package dependencies.
   
== Installing packages manually ==
 
  +
Please read the instructions for your package tool on how to set things up:
<span style="color: red; font-weight:bold; text-transform:uppercase">[WARNING: This rest of this page is extremely outdated and likely obsolete. It has barely been edited since 2013.]</span>
 
   
# First, ensure that all the packages it depends on are installed (by following these instructions recursively).
 
  +
* https://cabal.readthedocs.io/en/3.4/getting-started.html
# Unpack the tar file (Windows users: read [[How to unpack a tar file in Windows]] first):
 
  +
* https://docs.haskellstack.org/en/stable/README/#quick-start-guide
#:<code>tar xzf PACKAGE-VERSION.tar.gz</code>
 
# Move into the directory this creates:
 
#:<code>cd PACKAGE-VERSION</code>
 
# In order to install a package globally, perform the following commands (see the [http://www.haskell.org/cabal/users-guide/ Cabal documentation] for more details):
 
#:<code>runhaskell Setup configure</code>
 
#:<code>runhaskell Setup build</code>
 
#:On a Unix or Linux system:
 
#:<code>sudo runhaskell Setup install</code>
 
#:
 
#:Windows (login with administrator rights):
 
#:<code>runhaskell Setup install</code>
 
   
=== Notes ===
 
  +
== Installing an executable ==
# If instead of installing globally, you just wish to install a package for your normal user account, you could instead use the following <code>configure</code> command, which would register the install in the user-specific database and install binaries and libraries in $HOME/bin, $HOME/lib, and so forth (Windows users replace $HOME with %home%):
 
  +
#:<code>runhaskell Setup configure --user --prefix=$HOME</code>
 
  +
First, check your package site for binary releases. It may turn out you don't have to build anything.
#: (Note that in Cabal 1.4 onwards, you may omit the <code>--prefix=$HOME</code>, since <code>--prefix=$HOME/.cabal</code> is now implied by <code>--user</code>. Also note that you can omit <code>sudo</code> in the install statement if you use this method.)
 
  +
# You can get more information about any of these commands by adding <code>--help</code> after the command. For example, to see all the options available for the <code>configure</code> step, you could use the following command:
 
  +
If you have to build from source, clone a package repository and look for the project files it uses. Then build with the appropriate project tool.
#:<code>runhaskell Setup configure --help</code>
 
  +
# If you encounter unsatisfied dependencies when you run the configure step, that is when you recurse and first install the missing package.
 
  +
You may want to tweak the project file to use different options or dependency sets.
# If you have more than one Haskell compiler on your system, use the <code>--with-compiler</code> option for the <code>configure</code> step. That will ensure that Cabal uses the correct compiler during the entire installation process. For example:
 
  +
#: <code>runhaskell Setup configure --with-compiler=ghc-6.8.2</code>
 
  +
You may now use executables right from their build environment or copy them to your search $PATH.
#: <code>runhaskell Setup build</code>
 
#: On a Unix or Linux system:
 
#: <code>sudo runhaskell Setup install</code>
 
#:
 
#: Windows (login with administrator rights):
 
#: <code>runhaskell Setup install</code>
 

Latest revision as of 10:06, 10 March 2021


There's an interesting Haskell package on Hackage you'd like to try. How do you install it on your system?

Installing a library

While it is possible to "install" a library package "globally" it is most certainly a bad idea.

You should use project environment and package dependencies.

Please read the instructions for your package tool on how to set things up:

Installing an executable

First, check your package site for binary releases. It may turn out you don't have to build anything.

If you have to build from source, clone a package repository and look for the project files it uses. Then build with the appropriate project tool.

You may want to tweak the project file to use different options or dependency sets.

You may now use executables right from their build environment or copy them to your search $PATH.