installation.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. .. _installation:
  2. ************
  3. Installation
  4. ************
  5. There are several ways to install Agda:
  6. * Using a :ref:`released source <installation-from-hackage>` package
  7. from `Hackage <https://hackage.haskell.org/package/Agda>`_
  8. * Using a :ref:`binary package <prebuilt-packages>` prepared for your
  9. platform
  10. * Using the :ref:`development version
  11. <installation-development-version>` from the Git `repository
  12. <https://github.com/agda/agda>`_
  13. Agda can be installed using different flags (see :ref:`installation-flags`).
  14. .. _installation-from-hackage:
  15. .. hint:: If you want a sneak peek of Agda without installing it, try the
  16. `Agda Pad <agda-pad_>`_
  17. .. _agda-pad: https://agdapad.quasicoherent.io/
  18. Installation from source
  19. ========================
  20. .. _prerequisites:
  21. Prerequisites
  22. -------------
  23. You need recent versions of the following programs to compile Agda:
  24. * GHC: https://www.haskell.org/ghc/
  25. + Agda has been tested with GHC 8.0.2, 8.2.2, 8.4.4, 8.6.5, 8.8.4,
  26. 8.10.7, 9.0.1 and 9.2.1.
  27. * cabal-install: https://www.haskell.org/cabal/
  28. * Alex: https://www.haskell.org/alex/
  29. * Happy: https://www.haskell.org/happy/
  30. * GNU Emacs: http://www.gnu.org/software/emacs/
  31. You should also make sure that programs installed by *cabal-install*
  32. are on your shell's search path.
  33. Non-Windows users need to ensure that the development files for the C
  34. libraries *zlib* and *ncurses* are installed (see http://zlib.net
  35. and http://www.gnu.org/software/ncurses/). Your package manager may be
  36. able to install these files for you. For instance, on Debian or Ubuntu
  37. it should suffice to run
  38. .. code-block:: bash
  39. apt-get install zlib1g-dev libncurses5-dev
  40. as root to get the correct files installed.
  41. Optionally one can also install the `ICU
  42. <http://site.icu-project.org>`_ library, which is used to implement
  43. the :option:`--count-clusters` flag. Under Debian or Ubuntu it may suffice
  44. to install ``libicu-dev``. Once the ICU library is installed one can
  45. hopefully enable the :option:`--count-clusters` flag by giving the
  46. :option:`enable-cluster-counting` flag to *cabal install*:
  47. .. code-block:: bash
  48. cabal install -f enable-cluster-counting
  49. More information on installing the ICU prerequisite (like for other OSs)
  50. is available at
  51. https://github.com/haskell/text-icu/blob/master/README.markdown#prerequisites
  52. (retrieved 2022-02-09).
  53. Installing the ``agda`` and the ``agda-mode`` programs
  54. ------------------------------------------------------
  55. After installing the :ref:`prerequisites <prerequisites>` you can
  56. install the latest released version of Agda from `Hackage
  57. <https://hackage.haskell.org/package/Agda>`_.
  58. Using ``cabal``
  59. ^^^^^^^^^^^^^^^
  60. For installing the ``agda`` and the ``agda-mode`` programs using
  61. ``cabal`` run the following commands:
  62. .. code-block:: bash
  63. cabal update
  64. cabal install Agda
  65. If you use `Nix-style Local Builds
  66. <https://cabal.readthedocs.io/en/3.4/nix-local-build-overview.html>`_,
  67. by using Cabal ≥ 3.0 or by running ``cabal v2-install``, you'll get the
  68. following error when compiling with the GHC backend::
  69. Compilation error:
  70. MAlonzo/RTE.hs:13:1: error:
  71. Failed to load interface for ‘Numeric.IEEE’
  72. Use -v to see a list of the files searched for.
  73. This is because packages are sandboxed in ``$HOME/.cabal/store``
  74. and you have to explicitly register required packaged in a `GHC environment
  75. <https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/packages.html#package-environments>`_.
  76. This can be done by running the following command:
  77. .. code-block:: bash
  78. cabal v2-install --lib Agda ieee754
  79. This will register `ieee754
  80. <http://hackage.haskell.org/package/ieee754>`_ in the GHC default environment.
  81. You may want to keep the default environment clean, e.g. to avoid conflicts with
  82. other installed packages. In this case you can a create separate Agda
  83. environment by running:
  84. .. code-block:: bash
  85. cabal v2-install --package-env agda --lib Agda ieee754
  86. You then have to set the ``GHC_ENVIRONMENT`` when you invoke Agda:
  87. .. code-block:: bash
  88. GHC_ENVIRONMENT=agda agda -c hello-world.agda
  89. .. NOTE::
  90. Actually it is not necessary to register the Agda library,
  91. but doing so forces Cabal to install the same version of `ieee754
  92. <http://hackage.haskell.org/package/ieee754>`_ as used by Agda.
  93. .. Warning::
  94. If you are installing Agda using Cabal on Windows, depending on your
  95. system locale setting, ``cabal install Agda`` may fail with an error
  96. message:
  97. .. code-block:: bash
  98. hGetContents: invalid argument (invalid byte sequence)
  99. If this happens, you can try changing the `console code page <https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/chcp>`_
  100. to UTF-8 using the command:
  101. .. code-block:: bash
  102. CHCP 65001
  103. Using ``stack``
  104. ^^^^^^^^^^^^^^^
  105. For installing the ``agda`` and the ``agda-mode`` programs using
  106. ``stack`` run the following commands:
  107. .. code-block:: bash
  108. cabal get Agda-X.Y.Z
  109. cd Agda-X.Y.Z
  110. stack --stack-yaml stack-a.b.c.yaml install
  111. replacing `X.Y.Z` and `a.b.c` for the Agda version on Hackage and your
  112. GHC version, respectively.
  113. Running the ``agda-mode`` program
  114. ---------------------------------
  115. **Warning**: Intalling ``agda-mode`` via ``melpa`` is discouraged.
  116. It is stronly advised to install ``agda-mode`` for ``emacs`` as described below:
  117. After installing the ``agda-mode`` program using ``cabal`` or
  118. ``stack`` run the following command:
  119. .. code-block:: bash
  120. agda-mode setup
  121. The above command tries to set up Emacs for use with Agda via the
  122. :ref:`Emacs mode <emacs-mode>`. As an alternative you can copy the
  123. following text to your *.emacs* file:
  124. .. code-block:: emacs
  125. (load-file (let ((coding-system-for-read 'utf-8))
  126. (shell-command-to-string "agda-mode locate")))
  127. It is also possible (but not necessary) to compile the Emacs mode's
  128. files:
  129. .. code-block:: bash
  130. agda-mode compile
  131. This can, in some cases, give a noticeable speedup.
  132. **Warning**: If you reinstall the Agda mode without recompiling the
  133. Emacs Lisp files, then Emacs may continue using the old, compiled
  134. files.
  135. Installing the standard library
  136. -------------------------------
  137. Installing the standard library, should you choose to use it,
  138. is an additional step using `a separate repository <https://github.com/agda/agda-stdlib/blob/master/notes/installation-guide.md>`_.
  139. .. _prebuilt-packages:
  140. Prebuilt Packages and System-Specific Instructions
  141. ==================================================
  142. See also https://repology.org/project/agda/versions.
  143. Arch Linux
  144. ----------
  145. The following prebuilt packages are available:
  146. * `Agda <https://www.archlinux.org/packages/community/x86_64/agda/>`_
  147. * `Agda standard library <https://www.archlinux.org/packages/community/x86_64/agda-stdlib/>`_
  148. However, due to significant packaging bugs such as `this <https://bugs.archlinux.org/task/61904?project=5&string=agda>`_, you might want to use alternative installation methods.
  149. Debian / Ubuntu
  150. ---------------
  151. Prebuilt packages are available for Debian and Ubuntu from Karmic onwards. To install:
  152. .. code-block:: bash
  153. apt-get install agda-mode
  154. This should install Agda and the Emacs mode.
  155. The standard library is available in Debian and Ubuntu from Lucid onwards. To install:
  156. .. code-block:: bash
  157. apt-get install agda-stdlib
  158. More information:
  159. * `Agda (Debian) <https://tracker.debian.org/pkg/agda>`_
  160. * `Agda standard library (Debian) <https://tracker.debian.org/pkg/agda-stdlib>`_
  161. * `Agda (Ubuntu) <https://launchpad.net/ubuntu/+source/agda>`_
  162. * `Agda standard library (Ubuntu) <https://launchpad.net/ubuntu/+source/agda-stdlib>`_
  163. Reporting bugs:
  164. Please report any bugs to Debian, using:
  165. .. code-block:: bash
  166. reportbug -B debian agda
  167. reportbug -B debian agda-stdlib
  168. Fedora
  169. ------
  170. Agda is packaged in Fedora (since before Fedora 18).
  171. .. code-block:: bash
  172. yum install Agda
  173. will pull in emacs-agda-mode and ghc-Agda-devel.
  174. FreeBSD
  175. -------
  176. Packages are available from `FreshPorts
  177. <https://www.freebsd.org/cgi/ports.cgi?query=agda&stype=all>`_ for
  178. Agda and Agda standard library.
  179. Nix or NixOS
  180. ------------
  181. Agda is part of the Nixpkgs collection that is used by
  182. https://nixos.org/nixos. There are two ways to install Agda from nix:
  183. * The new way: If you are tracking ``nixos-unstable`` or
  184. ``nixpkgs-unstable`` (the default on MacOS) or you are using NixOS
  185. version 20.09 or above then you should be able to install Agda (and
  186. the standard library) via:
  187. .. code-block:: bash
  188. nix-env -f "<nixpkgs>" -iE "nixpkgs: (nixpkgs {}).agda.withPackages (p: [ p.standard-library ])"
  189. agda-mode setup
  190. echo "standard-library" > ~/.agda/defaults
  191. The second command tries to set up the Agda emacs mode. Skip this if
  192. you don't want to set up the emacs mode. See `Installation from
  193. source`_ above for more details about ``agda-mode setup``. The
  194. third command sets the ``standard-library`` as a default library so
  195. it is always available to Agda. If you don't want to do this you can
  196. omit this step and control library imports on a per project basis
  197. using an ``.agda-lib`` file in each project root.
  198. If you don't want to install the standard library via nix then you
  199. can just run:
  200. .. code-block:: bash
  201. nix-env -f "<nixpkgs>" -iA agda
  202. agda-mode setup
  203. For more information on the Agda infrastructure in nix, and how to
  204. manage and develop Agda libraries with nix, see
  205. https://nixos.org/manual/nixpkgs/unstable/#agda. In particular, the
  206. ``agda.withPackages`` function can install more libraries than just
  207. the standard library. Alternatively, see :ref:`Library Management
  208. <package-system>` for how to manage libraries manually.
  209. * The old way (deprecated): As Agda is a Haskell package available
  210. from Hackage you can install it like any other Haskell package:
  211. .. code-block:: bash
  212. nix-env -f "<nixpkgs>" -iA haskellPackages.Agda
  213. agda-mode setup
  214. This approach does not provide any additional support for working
  215. with Agda libraries. See :ref:`Library Management <package-system>`
  216. for how to manage libraries manually. It also suffers from this
  217. `open issue <https://github.com/agda/agda/issues/4613>`_ which the 'new
  218. way' does not.
  219. Nix is extremely flexible and we have only described how to install
  220. Agda globally using ``nix-env``. One can also declare which packages
  221. to install globally in a configuration file or pull in Agda and some
  222. relevant libraries for a particular project using ``nix-shell``.
  223. The Agda git repository is a `Nix flake <https://nixos.wiki/wiki/Flakes>`_
  224. to allow using a development version with Nix. The flake has the following
  225. outputs:
  226. - ``overlay``: A ``nixpkgs`` `overlay <https://nixos.wiki/wiki/Overlays>`_
  227. which makes ``haskellPackages.Agda`` (which the top-level ``agda``
  228. package depends on) be the build of the relevant checkout.
  229. - ``haskellOverlay``: An overlay for ``haskellPackages`` which overrides
  230. the ``Agda`` attribute to point to the build of the relevant checkout.
  231. This can be used to make the development version available at a different
  232. attribute name, or to override Agda for an alternative haskell package
  233. set.
  234. OS X
  235. ----
  236. `Homebrew <https://brew.sh>`_ is a free and open-source software package
  237. management system that provides prebuilt packages for OS X. Once it is
  238. installed in your system, you are ready to install agda. Open the
  239. Terminal app and run the following commands:
  240. .. code-block:: bash
  241. brew install agda
  242. agda-mode setup
  243. This process should take less than a minute, and it installs Agda together with
  244. its Emacs mode and its standard library. For more information about the ``brew``
  245. command, please refer to the `Homebrew documentation <https://docs.brew.sh/>`_
  246. and `Homebrew FAQ <https://docs.brew.sh/FAQ>`_.
  247. By default, the standard library is installed in the folder
  248. ``/usr/local/lib/agda/``. To use the standard library, it is
  249. convenient to add the location of the agda-lib file ``/usr/local/lib/agda/standard-library.agda-lib``
  250. to the ``~/.agda/libraries`` file, and write the line ``standard-library`` in
  251. the ``~/.agda/defaults`` file. To do this, run the following commands:
  252. .. code-block:: bash
  253. mkdir -p ~/.agda
  254. echo $(brew --prefix)/lib/agda/standard-library.agda-lib >>~/.agda/libraries
  255. echo standard-library >>~/.agda/defaults
  256. Please note that this configuration is not performed automatically. You can
  257. learn more about :ref:`using the standard library <use-std-lib>` or
  258. :ref:`using a library in general <use-lib>`.
  259. It is also possible to install with the command-line option keyword ``--HEAD``.
  260. This requires building Agda from source.
  261. To configure the way of editing agda files, follow the section
  262. :ref:`Emacs mode <emacs-mode>`.
  263. .. NOTE::
  264. If Emacs cannot find the ``agda-mode`` executable, it might help to
  265. install the exec-path-from-shell_ package by doing ``M-x
  266. package-install RET exec-path-from-shell RET`` and adding the line
  267. ``(exec-path-from-shell-initialize)`` to your ``.emacs`` file.
  268. Windows
  269. -------
  270. A precompiled version of Agda 2.6.0.1 bundled with Emacs 26.1 with the
  271. necessary mathematical fonts, is available at
  272. http://www.cs.uiowa.edu/~astump/agda.
  273. .. _installation-development-version:
  274. Installation of the Development Version
  275. =======================================
  276. After getting the development version from the Git `repository
  277. <https://github.com/agda/agda>`_
  278. * Install the :ref:`prerequisites <prerequisites>`
  279. * In the top-level directory of the Agda source tree, run:
  280. .. code-block:: bash
  281. cabal update
  282. make install
  283. Note that on a Mac, because ICU is installed in a non-standard location,
  284. you may need to set
  285. .. code-block:: bash
  286. export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"
  287. (cf. ``brew link icu4c``)
  288. or specify this location on the command line:
  289. .. code-block:: bash
  290. make install CABAL_OPTS='--extra-lib-dirs=/usr/local/opt/icu4c/lib --extra-include-dirs=/usr/local/opt/icu4c/include'
  291. You can also add the ``CABAL_OPTS`` variable to ``mk/config.mk`` (see
  292. ``HACKING.md``) instead of passing it via the command line.
  293. To install via ``stack`` instead of ``cabal``, copy one of the
  294. ``stack-x.x.x.yaml`` files of your choice to a ``stack.yaml`` file before
  295. running ``make``. For example:
  296. .. code-block:: bash
  297. cp stack-8.10.1.yaml stack.yaml
  298. make install
  299. .. _installation-flags:
  300. Installation Flags
  301. ==================
  302. When installing Agda the following flags can be used:
  303. .. option:: cpphs
  304. Use `cpphs <https://hackage.haskell.org/package/cpphs>`_ instead
  305. of cpp. Default: off.
  306. .. option:: debug
  307. Enable debugging features that may slow Agda down. Default: off.
  308. .. option:: enable-cluster-counting
  309. Enable the :option:`--count-clusters` flag. Note that if
  310. ``enable-cluster-counting`` is ``False``, then the
  311. :option:`--count-clusters` flag triggers an error
  312. message. Default: off.
  313. .. option:: optimise-heavily
  314. Optimise Agda heavily. (In this case it might make sense to limit
  315. GHC's memory usage.) Default: off.
  316. .. _exec-path-from-shell: https://github.com/purcell/exec-path-from-shell
  317. .. _installing-multiple-versions-of-Agda:
  318. Installing multiple versions of Agda
  319. ====================================
  320. Multiple versions of Agda can be installed concurrently by using the --program-suffix flag.
  321. For example:
  322. .. code-block:: bash
  323. cabal install Agda-2.6.1 --program-suffix=-2.6.1
  324. will install version 2.6.1 under the name agda-2.6.1. You can then switch to this version
  325. of Agda in Emacs via
  326. .. code-block:: bash
  327. C-c C-x C-s 2.6.1 RETURN
  328. Switching back to the standard version of Agda is then done by:
  329. .. code-block:: bash
  330. C-c C-x C-s RETURN