← 返回命令列表

Linux command

stack 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Create new project

stack new [project_name]

Build project

stack build

Run project executable

stack run

Run tests

stack test

Start REPL with project

stack ghci

Install package globally

stack install [package_name]

Execute Haskell file as script

stack script [script.hs]

Update package index

stack update

Show project paths

stack path

说明

stack is a build tool and project manager for Haskell. It provides reproducible builds by pinning GHC versions and package sets via Stackage snapshots. Stackage snapshots (LTS or Nightly) define curated package sets known to build together. This avoids "dependency hell" by ensuring compatible versions. The resolver in stack.yaml specifies which snapshot to use. Stack manages GHC installations automatically. Different projects can use different GHC versions without system-wide conflicts. The correct version downloads and builds on first use. Project structure includes stack.yaml (configuration), package.yaml (package definition), and source directories. Templates provide starting points for libraries, executables, or specific frameworks. The REPL (ghci) loads project code for interactive development. File watching (--file-watch) rebuilds on changes, enabling rapid iteration. Integration with Cabal packages works through package.yaml or .cabal files. Stack can use Hackage packages not in Stackage via extra-deps.

参数

new _NAME_ _TEMPLATE_
Create new project.
init
Initialize stack in existing project.
build
Build project.
run
Build and run executable.
test
Build and run tests.
bench
Build and run benchmarks.
ghci
Start REPL with project loaded.
install _PACKAGES_
Build and copy executables to bin.
exec _COMMAND_
Run command in build environment.
script _FILE_
Run a Haskell script.
setup
Download and install GHC for the project.
path
Display paths used by stack.
ls
List information (snapshots, dependencies, etc.).
clean
Clean build artifacts.
purge
Delete the stack working directories (clean --full).
upgrade
Upgrade stack itself.
--snapshot _SNAPSHOT_, --resolver _RESOLVER_
Stackage snapshot (e.g., lts-22.0, nightly-2025-01-01).
--system-ghc
Use system GHC instead of stack-managed.
--no-install-ghc
Don't automatically install GHC.
--fast
Disable optimizations for faster build.
--test
Enable test building.
--bench
Enable benchmark building.
--file-watch
Rebuild on file changes.
--ghc-options _OPTS_
Additional GHC options.

FAQ

What is the stack command used for?

stack is a build tool and project manager for Haskell. It provides reproducible builds by pinning GHC versions and package sets via Stackage snapshots. Stackage snapshots (LTS or Nightly) define curated package sets known to build together. This avoids "dependency hell" by ensuring compatible versions. The resolver in stack.yaml specifies which snapshot to use. Stack manages GHC installations automatically. Different projects can use different GHC versions without system-wide conflicts. The correct version downloads and builds on first use. Project structure includes stack.yaml (configuration), package.yaml (package definition), and source directories. Templates provide starting points for libraries, executables, or specific frameworks. The REPL (ghci) loads project code for interactive development. File watching (--file-watch) rebuilds on changes, enabling rapid iteration. Integration with Cabal packages works through package.yaml or .cabal files. Stack can use Hackage packages not in Stackage via extra-deps.

How do I run a basic stack example?

Run `stack new [project_name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does new _NAME_ _TEMPLATE_ do in stack?

Create new project.