LinuxCommandLibrary

crystal

statically-typed compiled language with Ruby-inspired syntax

TLDR

Run a Crystal program

$ crystal run [path/to/file.cr]
copy
Compile to an executable
$ crystal build [path/to/file.cr]
copy
Compile with optimizations (release mode)
$ crystal build --release [path/to/file.cr]
copy
Start a new project
$ crystal init app [project_name]
copy
Run the project's spec tests
$ crystal spec
copy
Check code for errors without compiling
$ crystal tool format --check [path/to/file.cr]
copy
Format source code
$ crystal tool format [path/to/file.cr]
copy
Generate documentation
$ crystal docs
copy

SYNOPSIS

crystal [command] [options] [file] [--] [arguments]

DESCRIPTION

crystal is the command-line interface for the Crystal programming language. Crystal is a statically-typed, compiled language with Ruby-inspired syntax that aims for C-level performance with programmer-friendly ergonomics.
The primary commands are run for quick execution during development and build for creating distributable binaries. Crystal compiles through LLVM, producing native machine code. The --release flag enables optimizations for production builds.
Crystal uses a specification-based testing framework. The spec command runs tests from the spec/ directory. The test syntax resembles RSpec from Ruby, making it familiar to Ruby developers.
The init command scaffolds new projects with standard directory structure, shard.yml (dependency manifest), and initial files. Dependencies (shards) are managed separately with the shards command, similar to Bundler in Ruby.
Crystal includes built-in code formatting and documentation generation. The playground provides an interactive web-based environment for experimenting with code.

PARAMETERS

run file

Compile and run the program.
build file
Compile to an executable.
spec
Run the project's spec test suite.
init type name
Create a new Crystal project (app or lib).
docs
Generate API documentation.
tool format files
Format Crystal source code.
tool hierarchy type
Show type hierarchy.
tool implement type
Show implementation of a method.
play
Start the Crystal playground web server.
--release
Compile in release mode with optimizations.
-o, --output file
Specify output executable name.
--progress
Show compilation progress.
--no-color
Disable colored output.
-D, --define flag
Define a compile-time flag.
--static
Link statically.
--cross-compile
Generate object file for cross-compilation.

CAVEATS

Compilation can be slow and memory-intensive for large projects. Cross-compilation requires specific setup. Some Ruby syntax patterns don't translate directly. The standard library is smaller than more established languages. Static linking may require additional system libraries.

HISTORY

Crystal was created by Ary Borenszweig and Juan Wajnerman, with development starting in 2011 and the first public release in 2014. The language was designed to combine Ruby's expressiveness with static typing and native performance. Version 1.0 was released in March 2021, marking the language's production readiness.

SEE ALSO

shards(1), ruby(1), rustc(1), llvm(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community