crystal
Compile and run Crystal programming language code
TLDR
Run a Crystal file
Compile a file and all dependencies to a single executable
Read Crystal source code from the command-line or stdin, and execute it
Generate API documentation from inline docstrings in Crystal files
Compile and run a Crystal specification suite
Start a local interactive server for testing the language
Create a project directory for a Crystal application
Display help
SYNOPSIS
crystal [global options...] <command> [<args>...]
PARAMETERS
-D STRING, --define=STRING
Set a compiler-time constant (e.g., -Dflag)
-e STRING, --eval=STRING
Evaluate Crystal code from string directly
-h, --help
Display help message for crystal or subcommand
--no-color
Disable colored output
-v, --version
Print Crystal version and exit
--verbose
Enable verbose logging
DESCRIPTION
The crystal command is the primary CLI tool for the Crystal programming language, a high-performance, statically-typed language with Ruby-inspired syntax. It compiles Crystal code to native machine code rivaling C's speed while maintaining Ruby's elegance and productivity. Garbage-collected and thread-safe, Crystal excels in web servers, CLI apps, and systems programming.
Key workflows include scaffolding projects with crystal init, compiling executables via crystal build, executing scripts with crystal run, testing with crystal spec, and formatting code using crystal fmt. It supports macros, C interop, fibers for concurrency, and a rich stdlib. Global options apply across subcommands, enabling defines, eval, and version checks.
Ideal for developers seeking Ruby's joy with compiled efficiency, Crystal powers tools like Lucky framework and Amber. Install via official packages or source for Linux, macOS, and more.
CAVEATS
Not a standard Linux utility; requires Crystal installation. LLVM backend needed for compilation. Cross-compilation experimental.
COMMON SUBCOMMANDS
build: Compile .cr to executable
run: Build and execute source file
spec: Run test specs
init: Scaffold app or lib project
fmt: Format source code
docs: Generate documentation
EXAMPLE USAGE
crystal init app myapp – create app
crystal build src/myapp.cr -o myapp – compile binary
crystal spec – test suite
HISTORY
Initiated in 2011 by Ary Borenszweig at Manas. Pre-1.0 releases from 2014. Stable 1.0 in March 2018. Evolved with shards packaging (now integrated), fibers, and better C bindings. Version 1.11+ (2024) adds generics improvements.


