갈루아의 반서재

cabal은 하스켈로 작성된 소프트웨어를 다운로드받고 빌딩하는 명령프로그램이다. 이를 통해 Hackage repository 에 존재하는 모든 패키지를 다운받아 설치할 수 있다. 가끔 알수없는 오류를 일으키기도 하는데 본 포스팅읉 통해 올바른 cabal 패키지 설치방법을 알아보자. 


cabal, Cabal, cabal-install

혼동을 피하기 위해 먼저 Cabal wiki page 의 설명을 먼저 보자.

"Cabal 은 패키지 및 빌드 시스템이다. Cabal 은 단지 패키지의 생성과 그 컨텐츠의 빌딩에만 관여한다. 패키지를 관리하지는 않는다. Cabal-Install 은 카발 패키지를 설치한다. 그것은 빌드시스템인 Cabal 과는 구분된다. 이러한 점들은 종종 새로운 사용자들에게 혼동을 일으킨다. 게다가 Cabal-Install 은 풀 기능을 가진 패키지 매니저가 아니다. 예를 들어, non cabal packaged dependencies 는 설치할 수 없고, 패키지 제거도 안되며, 업그레이드 설치도 자동으로 이루어지지 않는다.


Cabal 설치


Cabal은 Haskell Platform을 설치하거나 GHC 를 통해 설치할 수 있다. 다음과 같이 설치 여부를 확인한다.

1
2
3
# cabal --version
cabal-install version 1.22.6.0
using version 1.22.5.0 of the Cabal library
cs

구버전이 설치되어 있다면 아래와 같이 업데이트가 가능하다. 다음과 같은 메시지가 나오면서 업데이트가 되지 않는 경우에는 config 파일을 삭제한 후 업데이트를 시도하면 된다 

1
2
3
4
# cabal update
Warning: /root/.cabal/config: Unrecognized stanza on line 14
Warning: No remote package servers have been specified. Usually you would have
one specified in the config file.
cs

/root/.cabal/config 파일 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
-- This is the configuration file for the 'cabal' command line tool.
 
-- The available configuration options are listed below.
-- Some of them have default values listed.
 
-- Lines (like this one) beginning with '--' are comments.
-- Be careful with spaces and indentation because they are
-- used to indicate layout for nested sections.
 
-- Cabal library version: 1.24.2.0
-- cabal-install version: 1.24.0.2
 
 
repository hackage.haskell.org
  url: http://hackage.haskell.org/
  -- secure: False
  -- root-keys:
  -- key-threshold:
cs

다시 시도해보자. 정상적으로 다운로딩이 되었다.

1
2
3
4
5
# cabal update
Config file path source is default config file.
Config file /root/.cabal/config not found.
Writing default configuration to /root/.cabal/config
Downloading the latest package list from hackage.haskell.org
cs

업데이트가 완료되었으면 설치한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
(blackbriar) root@gcloudx:~/blackbriar/blackbriar# cabal install cabal-install
Resolving dependencies...
Downloading Cabal-2.0.1.1...
Configuring Cabal-2.0.1.1...
Building Cabal-2.0.1.1...
Preprocessing library Cabal-2.0.1.1...
.
.
.
Linking dist/build/cabal/cabal ...
Generating manual page dist/build/cabal/cabal.1 ...
Installing executable(s) in /root/.cabal/bin
Installed cabal-install-2.0.0.1
cs


패키지 설치


다음과 같은 과정을 통해 패키지를 설치할 수 있다.


  1. 설치를 원하는 패키지를 Hackage package list  나 cabal list
  2. cabal update로컬 리스트에 존재하는 packages 와 dependencies 업데이트시
  3. cabal install PACKAGE를 이용하여 다운로드하여 설치한다
    유용한 옵션:
    --dry-run : cabal plans 를 확인할 때 (recommended),
    -jN : 병렬로 N 패키지 설치
    -fFLAG 또는 -f-FLAG : 추가적인 빌드 플래그를 온 또는 오프 할 때 


설치된 패키지 확인하기


다음과 같이 패키지의 설치 유무를 확인할 수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
 
# cabal list --installed yesod-sitemap
* yesod-sitemap
    Synopsis: Generate XML sitemaps.
    Default available version: 1.6.0
    Installed versions: 1.4.0.1
    Homepage: http://www.yesodweb.com/
    License:  MIT
 
# cabal list --installed Diff
No matches found.
 
cs


ghc-pkg를 이용해서도 마찬가지 결과를 얻을 수 있다.

1
2
3
4
5
6
7
8
# ghc-pkg list
/usr/lib/ghc/package.conf.d
   yesod-sitemap-1.4.0.1
 
# ghc-pkg list yesod-sitemap
/usr/lib/ghc/package.conf.d
/root/.ghc/x86_64-linux-7.10.3/package.conf.d
   yesod-sitemap-1.4.0.1
cs


패키지 다른 패키지에서 사용하기 위한 libraries 나 사용자가 사용하기 위한 executables 또는 양자 모두를 포함한다. cabal 과 ghc-pkg 는 설치된 라이브러리 패키지만 추적할 수 있다. 예를 들어, shelltestrunner 패키지는 executables 형태로만 제공되므로 cabal 이나 ghc-pkg 으로는 그 설치 유무를 확인할 수 없다. 


[원문보기] https://www.schoolofhaskell.com/user/simonmichael/how-to-cabal-install