← 返回命令列表

Linux command

crystal 命令

文件

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

常用示例

Run a Crystal program

crystal run [path/to/file.cr]

Compile to an executable

crystal build [path/to/file.cr]

Compile with optimizations

crystal build --release [path/to/file.cr]

Start a new project

crystal init app [project_name]

Run the project's spec tests

crystal spec

Check formatting

crystal tool format --check [path/to/file.cr]

Format source code

crystal tool format [path/to/file.cr]

Generate documentation

crystal docs

说明

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.

参数

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.

FAQ

What is the crystal command used for?

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.

How do I run a basic crystal example?

Run `crystal run [path/to/file.cr]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does run _file_ do in crystal?

Compile and run the program.