Hello World in Crystal

Our first program will print the classic “hello world” message. Here’s the full source code.

# This is a simple Crystal program that prints "hello world" to the console.
puts "hello world"

To run the program, save the code in a file named hello_world.cr and use the crystal command.

$ crystal run hello_world.cr
hello world

Sometimes we’ll want to build our programs into binaries. We can do this using the crystal build command.

$ crystal build hello_world.cr
$ ls
hello_world    hello_world.cr

We can then execute the built binary directly.

$ ./hello_world
hello world

Now that we can run and build basic Crystal programs, let’s learn more about the language.