Hello World in Nim

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

echo "hello world"

To run the program, put the code in hello_world.nim and use the nim command.

$ nim compile --run hello_world.nim
hello world

Sometimes we’ll want to build our programs into binaries. We can do this using nim c.

$ nim c -o:hello_world hello_world.nim
$ ls
hello_world  hello_world.nim

We can then execute the built binary directly.

$ ./hello_world
hello world

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