不说废话,直接上干货,操作步骤一步一步来,中间穿插过程中遇到的各种问题。
1. 安装stack
[zhy@v-zhy ~] # su -
[root@v-zhy ~] # curl -sSL https://s3.amazonaws.com/download.fpcomplete.com/centos/7/fpco.repo | tee /etc/yum.repos.d/fpco.repo
[root@v-zhy ~] # yum -y install stack
2. 获取pandoc源码
[root@v-zhy ~] # git clone https://github.com/jgm/pandoc
3. 安装pandoc
[root@v-zhy ~] # cd pandoc
[root@v-zhy pandoc] # stack setup
Could not parse '/root/pandoc/stack.yaml':
Aeson exception:
Error in $['ghc-options']: failed to parse field 'ghc-options': Invalid package name: "$locals"
See http://docs.haskellstack.org/en/stable/yaml_configuration/
- 遇到第一个问题,pandoc说明中有介绍,需要 stack版本>=1.7.0
[root@v-zhy pandoc] # stack --version
Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e (4861 commits) x86_64 hpack-0.17.1
通过查看,发现已安装的stack版本为1.5.1,不符合pandoc要求,需要升级
4. 升级stack
[root@v-zhy pandoc] # stack upgrade
Current Stack version: 1.5.1, available download version: 2.1.3
Newer version detected, downloading
Querying for archive location for platform: linux-x86_64-static
Downloading from: https://github.com/commercialhaskell/stack/releases/download/v2.1.3/stack-2.1.3-linux-x86_64-static.tar.gz
Download complete, testing executable
Version 2.1.3, Git revision 636e3a759d51127df2b62f90772def126cdf6d1f (7735 commits) x86_64 hpack-0.31.2
WARNING: The "stack" executable found on the PATH environment variable is /usr/bin/stack, and not the version that was just installed.
This means that "stack" calls on the command line will not use this version.
New stack executable available at /root/.local/bin/stack
[root@v-zhy pandoc] # stack --version
Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e (4861 commits) x86_64 hpack-0.17.1
执行stack upgrade
后发现版本没有变化,原因就是升级信息的最后三行信息,新版本的stack执行程序放到了 /root/.local/bin/stack
位置,而不是/usr/bin/stack
,所以讲新版本的复制到/usr/bin/
目录内即可。
[root@v-zhy pandoc] # cp /root/.local/bin/stack /usr/bin/
cp:是否覆盖"/usr/bin/stack"? yes
[root@v-zhy pandoc] # stack --version
Version 2.1.3, Git revision 636e3a759d51127df2b62f90772def126cdf6d1f (7735 commits) x86_64 hpack-0.31.2
5. 预备安装pandoc(stack setup)
[root@v-zhy pandoc] # stack setup
Exception while reading snapshot from lts-14.6:
HttpExceptionRequest Request {
host = "raw.githubusercontent.com"
port = 443
secure = True
requestHeaders = [("User-Agent","Haskell pantry package")]
path = "/commercialhaskell/stackage-snapshots/master/lts/14/6.yaml"
queryString = ""
method = "GET"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
}
(InternalException (HostCannotConnect "raw.githubusercontent.com" [Network.Socket.connect: <socket: 13>: does not exist (Connection refused)]))
- 遇到第二个问题,连接raw.githubusercontent.com被拒绝。可以通过重新将pandoc项目切换到github源。
[root@v-zhy pandoc] # git remote set-url origin git@github.com:jgm/pandoc.git
[root@v-zhy pandoc] # git pull
这里重复执行stack setup
应该可以解决。
[root@v-zhy pandoc] # stack setup
...
HttpExceptionRequest Request {
host = "s3.amazonaws.com"
port = 443
secure = True
requestHeaders = [("User-Agent","Haskell pantry package")]
path = "/hackage.fpcomplete.com/package/pandoc-types-1.20.tar.gz"
queryString = ""
method = "GET"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
}
ConnectionTimeout
- 遇到第三个问题,这里会遇到一系列类似问题,基本都是由于网络原因,可以重复执行
stack setup
解决,如果期间遇到长时间卡顿,也可以中止然后重新执行stack setup
。
[root@v-zhy pandoc] # stack setup
...
Preparing to install GHC to an isolated location.
This will not interfere with any system-level installation.
Downloaded ghc-8.6.5.
rts-1.0: Warning: .:464:1: The field "hugs-options" is deprecated. hugs isn't supported anymore
Installed GHC.
stack will use a sandboxed GHC it installed
For more information on paths, see 'stack path' and 'stack exec env'
To use this GHC and packages outside of a project, consider using:
stack ghc, stack ghci, stack runghc, or stack exec
看到以上信息,说明这一步执行完成,可以继续操作了。
6. 安装pandoc(stack install)
[root@v-zhy pandoc] # stack install
...
HttpExceptionRequest Request {
host = "s3.amazonaws.com"
port = 443
secure = True
requestHeaders = [("User-Agent","Haskell pantry package")]
path = "/hackage.fpcomplete.com/package/split-0.2.3.3.tar.gz"
queryString = ""
method = "GET"
proxy = Nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
}
(InternalException (HandshakeFailed (Error_Misc "Network.Socket.recvBuf: resource vanished (Connection reset by peer)")))
这一步比较耗时,总共有104个progress需要安装注册,期间多次遇到类似上面的问题,可通过重复执行stack install
来解决。
[root@v-zhy pandoc] # stack install
...
Preprocessing executable 'pandoc' for pandoc-2.9.1.1..
Building executable 'pandoc' for pandoc-2.9.1.1..
[1 of 2] Compiling Main
[2 of 2] Compiling Paths_pandoc
Linking .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/pandoc/pandoc ...
pandoc > copy/register
Installing library in /workspace/pandoc/.stack-work/install/x86_64-linux/b581e8d7a02f6e87241fa0370f9c7193981bf365910d24506c9480dbd244429d/8.6.5/lib/x86_64-linux-ghc-8.6.5/pandoc-2.9.1.1-KCFMVYOSGB29fGCfwM6Osy
Installing executable pandoc in /workspace/pandoc/.stack-work/install/x86_64-linux/b581e8d7a02f6e87241fa0370f9c7193981bf365910d24506c9480dbd244429d/8.6.5/bin
Registering library for pandoc-2.9.1.1..
Completed 10 action(s).
Copying from /workspace/pandoc/.stack-work/install/x86_64-linux/b581e8d7a02f6e87241fa0370f9c7193981bf365910d24506c9480dbd244429d/8.6.5/bin/pandoc to /root/.local/bin/pandoc
Copied executables to /root/.local/bin:
- pandoc
看到以上信息时,说明pandoc已经安装完成。
[root@v-zhy pandoc] # stack -v
pandoc 2.9.1.1
Compiled with pandoc-types 1.20, texmath 0.12, skylighting 0.8.3
Default user data directory: /root/.local/share/pandoc or /root/.pandoc
Copyright (C) 2006-2019 John MacFarlane
Web: https://pandoc.org
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.