LoginSignup
3
0

More than 1 year has passed since last update.

さくらのレンタルサーバ スタンダードに Haskell 環境を構築する手順(2022 年版)

Posted at

さくらのレンタルサーバ スタンダードに Haskell 環境を構築する手順 は FreeBSD 9.1 に Haskell 開発環境を構築する手順でしたが、私の環境もようやく 2022-08-31 に FreeBSD 12 に更新され、まともな開発環境が再構築できるようになりました。

この FreeBSD 12 に Haskell 開発環境を構築します。

GHCup 導入

GHCup は GHC や Stack などのインストールを管理するツールです。Stack 上の curl コマンドで stack コマンドを直接インストールすれば簡単なのですが、FreeBSD は Stack のスクリプトでサポートされていないため、GHCup 経由で行きます。しかしながら長期的に複数の GHC や Stack を管理することになるかも知れないため、GHCup は良い選択かも知れません。

$ curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

Welcome to Haskell!

This script can download and install the following binaries:
  * ghcup - The Haskell toolchain installer
  * ghc   - The Glasgow Haskell Compiler
  * cabal - The Cabal build tool for managing Haskell software
  * stack - (optional) A cross-platform program for developing Haskell projects
  * hls   - (optional) A language server for developers to integrate with their editor/IDE

ghcup installs only into the following directory,
which can be removed anytime:
  /home/xxx/.ghcup

Press ENTER to proceed or ctrl-c to abort.
Note that this script can be re-run at any given time.

-------------------------------------------------------------------------------

Detected bash shell on your system...
Do you want ghcup to automatically add the required PATH variable to "/home/xxx/.bashrc"?

[P] Yes, prepend  [A] Yes, append  [N] No  [?] Help (default is "P").

A
-------------------------------------------------------------------------------
Do you want to install haskell-language-server (HLS)?
HLS is a language-server that provides IDE-like functionality
and can integrate with different editors, such as Vim, Emacs, VS Code, Atom, ...
Also see https://haskell-language-server.readthedocs.io/en/stable/

[Y] Yes  [N] No  [?] Help (default is "N").

N
-------------------------------------------------------------------------------
Do you want to install stack?
Stack is a haskell build tool similar to cabal that is used by some projects.
Also see https://docs.haskellstack.org/

[Y] Yes  [N] No  [?] Help (default is "N").

Y
13.0-RELEASE-p12
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 67.3M  100 67.3M    0     0  25.3M      0  0:00:02  0:00:02 --:--:-- 25.3M
[ Info  ] downloading: https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-0.0.7.yaml as file /home/xxx/.ghcup/cache/ghcup-0.0.7.yaml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
[ Info  ] Upgrading GHCup...
[ Warn  ] No GHCup update available

System requirements
  Please ensure the following distro packages are installed before continuing (you can exit ghcup and return at any time): curl gcc gmp gmake ncurses perl5 libffi libiconv
Press ENTER to proceed or ctrl-c to abort.
Installation may take a while.


[ Info  ] downloading: https://downloads.haskell.org/~ghc/8.10.7/ghc-8.10.7-x86_64-unknown-freebsd.tar.xz as file /home/xxx/.ghcup/cache/ghc-8.10.7-x86_64-unknown-freebsd.tar.xz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  170M  100  170M    0     0  25.8M      0  0:00:06  0:00:06 --:--:-- 29.1M
[ Info  ] verifying digest of: ghc-8.10.7-x86_64-unknown-freebsd.tar.xz
[ Info  ] Unpacking: ghc-8.10.7-x86_64-unknown-freebsd.tar.xz to /home/xxx/.ghcup/tmp/ghcup-3d60f2a266d90484
[ Info  ] Installing GHC (this may take a while)
[ Info  ] Merging file tree from "/home/xxx/.ghcup/tmp/ghcup-55050b90ee2b4e29/home/xxx/.ghcup/ghc/8.10.7" to "/home/xxx/.ghcup/ghc/8.10.7"
[ Info  ] GHC installation successful
[ Info  ] GHC 8.10.7 successfully set as default version
[ Info  ] downloading: https://downloads.haskell.org/~cabal/cabal-install-3.6.2.0/cabal-install-3.6.2.0-x86_64-freebsd13.tar.xz as file /home/xxx/.ghcup/cache/cabal-install-3.6.2.0-x86_64-freebsd13.tar.xz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 5923k  100 5923k    0     0  17.0M      0 --:--:-- --:--:-- --:--:-- 17.0M
[ Info  ] verifying digest of: cabal-install-3.6.2.0-x86_64-freebsd13.tar.xz
[ Info  ] Unpacking: cabal-install-3.6.2.0-x86_64-freebsd13.tar.xz to /home/xxx/.ghcup/tmp/ghcup-3e36172017b03fd1
[ Info  ] Installing cabal
[ Info  ] Cabal installation successful
Config file path source is default config file.
Config file /home/xxx/.cabal/config not found.
Writing default configuration to /home/xxx/.cabal/config
Downloading the latest package list from hackage.haskell.org
Updated package list of hackage.haskell.org to the index-state 2022-09-11T10:29:54Z
[ Warn  ] stack-2.7.5 is already installed; if you really want to reinstall it, you may want to run 'ghcup install cabal --force 2.7.5'

===============================================================================

OK! /home/xxx/.bashrc has been modified. Restart your terminal for the changes to take effect,
or type "source /home/xxx/.ghcup/env" to apply them in your current terminal session.

===============================================================================

All done!

To start a simple repl, run:
  ghci

To start a new haskell project in the current directory, run:
  cabal init --interactive

To install other GHC versions and tools, run:
  ghcup tui

If you are new to Haskell, check out https://www.haskell.org/ghcup/steps/
$ echo 'export PATH=$HOME/.local/bin:$PATH' >>~/.bashrc
$ exec -l $SHELL
$ ghcup tui
┌────────────────────────────────GHCup────────────────────────────────┐
│    Tool  Version         Tags                          Notes        │
│─────────────────────────────────────────────────────────────────────│
│✔✔  GHCup 0.1.18.0        latest,recommended                         │
│─────────────────────────────────────────────────────────────────────│
│✔✔  Stack 2.7.5           latest,recommended                         │
│─────────────────────────────────────────────────────────────────────│
│✗   HLS   1.7.0.0         latest,recommended                         │
│─────────────────────────────────────────────────────────────────────│
│✗   cabal 3.8.1.0         latest                                     │
│✔✔  cabal 3.6.2.0         recommended                                │
│─────────────────────────────────────────────────────────────────────│
│✗   GHC   9.4.2           latest,base-4.17.0.0                       │
│✗   GHC   9.2.4           base-4.16.3.0                              │
│✗   GHC   9.0.2           base-4.15.1.0                              │
│✔✔  GHC   8.10.7          recommended,base-4.14.3.0                  │
│✗   GHC   8.8.4           base-4.13.0.0                              │
│✗   GHC   8.6.5           base-4.12.0.0                              │
│✗   GHC   8.4.4           base-4.11.1.0                              │
└─────────────────────────────────────────────────────────────────────┘
q:Quit  i:Install  u:Uninstall  s:Set  c:ChangeLog  a:Show all versions
t:Show all tools  ↑:Up  ↓:Down
q
$ stack new hoge
...
$ cd hoge
$ stack build
...
$ stack run
someFunc
$

問題なく動作しているようです。

インストール途中に以下のメッセージが表示されましたが、私の環境にはすべて揃っていました。

System requirements
  Please ensure the following distro packages are installed before continuing (you can exit ghcup and return at any time): curl gcc gmp gmake ncurses perl5 libffi libiconv
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0