LinuxCommandLibrary

crystal

Compile and run Crystal programming language code

TLDR

Run a Crystal file

$ crystal [path/to/file.cr]
copy

Compile a file and all dependencies to a single executable
$ crystal build [path/to/file.cr]
copy

Read Crystal source code from the command-line or stdin, and execute it
$ crystal eval '[code]'
copy

Generate API documentation from inline docstrings in Crystal files
$ crystal docs
copy

Compile and run a Crystal specification suite
$ crystal spec
copy

Start a local interactive server for testing the language
$ crystal play
copy

Create a project directory for a Crystal application
$ crystal init app [application_name]
copy

Display help
$ crystal help
copy

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 &#x2013; create app
crystal build src/myapp.cr -o myapp &#x2013; compile binary
crystal spec &#x2013; 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.

SEE ALSO

gcc(1), clang(1), ruby(1), go(1)

Copied to clipboard