In Crystal, code is imported with the require statement.


# Import from the current directory. 
# OR import from the ./stuff/ directory if it exists. 
require "./stuff"

# Explicitly import the file from the 
# current directory.
require "./"

# Import from parent directory.
require "../stuff"

# Import from N parent level directories.
require "../../stuff"

# Import from a subdirectory.
require "./stuff/things"

# Import all .cr files in the current directory.
require "./stuff/*"

# Import all .cr files in the current and sub directories.
require "./stuff/**"

# Import or stuff/ from the standard library.
# OR import or stuff/ from the ./lib directory.
require "stuff"


  • The compiler combines all required files together.
  • A file can be required more than once, but only the first require statement has any effect.
  • The standard library on Linux is located in the /opt/crystal/src/ directory.