如何在Windows,Linux中安装、设置Haskell平台?

628 阅读4分钟

这篇文章包括如何在windows和linux中设置、安装haskell platform 环境。

你也可以查看其他关于haskell教程的帖子

Haskell平台环境

这是一个在多个环境中设置和运行Haskell代码的快速方法。

这个平台带有以下软件包

  • ghc(Glasgow Haskell Compiler)编译器
  • cabal构建系统来构建Haskell代码
  • 包括30多个内建包

在windows下安装或设置 - GHC,cabal

前提条件安装Haskell需要以下条件

  • 安装Chocolatey或choco命令

请确保在你的机器上安装chocolatey,请检查chocolatey的安装

在我的系统中,我已经安装了choco命令,请在命令控制台中发出choco命令来检查安装情况或信息。

C:\Users>choco
Chocolatey v0.10.15
Please run 'choco -?' or 'choco  -?' for help menu.

Chocolatey已经安装了v0.10.15版本。

所以现在可以在windows机器上安装Haskell平台了。

接下来使用choco安装haskell-dev

我试着用下面的命令在命令提示符下运行,但得到的信息是 "Chocolatey检测到你没有从一个升高的命令外壳中运行"。

我们需要从Powershell运行命令choco install haskell-dev

下面是输出结果:

C:\Users>choco install haskell-dev
Chocolatey v0.10.15
Chocolatey detected you are not running from an elevated command shell
 (cmd/powershell).

 You may experience errors - many functions/packages
 require admin rights. Only advanced users should run choco w/out an
 elevated shell. When you open the command shell, you should ensure
 that you do so with "Run as Administrator" selected. If you are
 attempting to use Chocolatey in a non-administrator setting, you
 must select a different location other than the default install
 location. See
 https://chocolatey.org/install#non-administrative-install for details.


 Do you want to continue?([Y]es/[N]o): No

在Windows搜索框中输入Windows Powershell

用管理角色打开shell

PS C:\WINDOWS\system32> choco install haskell-dev
Chocolatey v0.10.15
Installing the following packages:
Haskell-dev
By installing you accept licenses for the packages.

cabal v3.2.0.0 [Approved]
cabal package files install completed. Performing other installation steps.
The package cabal wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): Y

Downloading cabal 64 bit
  from 'https://downloads.haskell.org/cabal/cabal-install-3.2.0.0/cabal-install-3.2.0.0-x86_64-unknown-mingw32.zip'
Progress: 100% - Completed download of C:\Users\Kiran\AppData\Local\Temp\chocolatey\cabal\3.2.0.0\cabal-install-3.2.0.0-x86_64-unknown-mingw32.zip (5.15 MB).
Download of cabal-install-3.2.0.0-x86_64-unknown-mingw32.zip (5.15 MB) completed.
Hashes match.
Extracting C:\Users\Kiran\AppData\Local\Temp\chocolatey\cabal\3.2.0.0\cabal-install-3.2.0.0-x86_64-unknown-mingw32.zip to C:\ProgramData\chocolatey\lib\cabal\tools\cabal-3.2.0.0...
C:\ProgramData\chocolatey\lib\cabal\tools\cabal-3.2.0.0
Could not read cabal configuration key 'install-method'.
Updated cabal configuration.
PATH environment variable does not have C:\Users\Kiran\AppData\Roaming\cabal\bin in it. Adding...
Adding C:\ProgramData\chocolatey\bin\mingw64-pkg.bat and pointing it to powershell command C:\ProgramData\chocolatey\lib\cabal\tools\mingw64-pkg.ps1
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 ShimGen has successfully created a shim for cabal.exe
 The install of cabal was successful.
  Software installed to 'C:\ProgramData\chocolatey\lib\cabal\tools\cabal-3.2.0.0'

ghc v8.10.1 [Approved]
ghc package files install completed. Performing other installation steps.
The package ghc wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): Y

Downloading ghc 64 bit
  from 'https://downloads.haskell.org/~ghc/8.10.1/ghc-8.10.1-x86_64-unknown-mingw32.tar.xz'
Progress: 100% - Completed download of C:\ProgramData\chocolatey\lib\ghc\tmp\ghcInstall (407.68 MB).
Download of ghcInstall (407.68 MB) completed.
Hashes match.
C:\ProgramData\chocolatey\lib\ghc\tmp\ghcInstall
Extracting C:\ProgramData\chocolatey\lib\ghc\tmp\ghcInstall to C:\ProgramData\chocolatey\lib\ghc\tools...
C:\ProgramData\chocolatey\lib\ghc\tools
Extracting C:\ProgramData\chocolatey\lib\ghc\tools\ghcInstall~ to C:\ProgramData\chocolatey\lib\ghc\tools...
C:\ProgramData\chocolatey\lib\ghc\tools
PATH environment variable does not have C:\ProgramData\chocolatey\lib\ghc\tools\ghc-8.10.1\bin in it. Adding...
Hiding shims for 'C:\ProgramData\chocolatey\lib\ghc\tools'.
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 The install of ghc was successful.
  Software installed to 'C:\ProgramData\chocolatey\lib\ghc\tools'

haskell-dev v0.0.1 (forced) [Approved]
haskell-dev package files install completed. Performing other installation steps.
 The install of haskell-dev was successful.
  Software install location not explicitly set, could be in package or
  default install location if installer.

Chocolatey installed 2/2 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Haskell平台的安装对环境变量进行了修改。请关闭PowerShell或运行下面的命令来获取环境变量的变化。

PS C:\WINDOWS\system32> refreshenv
Refreshing environment variables from the registry for cmd.exe. Please wait...Finished..

现在Haskell平台已经成功地安装在windows中,你已经准备好享受编写Haskell代码了。

在Ubuntu和Linux上设置Haskell平台

Haskell平台为每个版本的操作系统提供了来自存储库的安装包

对于Linuxdebian```来说

sudo yum install haskell-platform

对于[ubuntu](https://packages.ubuntu.com/search?keywords=haskell-platform)

sudo apt-get install haskell-platform

对于[fedora linux] (https://admin.fedoraproject.org/pkgdb/package/haskell-platform/)

sudo dnf install haskell-platform

检查Haskell编译器--GHC,cabal是否安装。

你可以安装Haskell平台以获得快速和简单的安装,或者你可以使用单独的软件包。

请发布以下命令:ghc commandcabal command

B:\haskell>ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.1

B:\haskell>cabal --version
cabal-install version 3.2.0.0
compiled using version 3.2.0.0 of the Cabal library