Hello Raku
Welcome to Raku! Whether you are coming from Perl, Python, or this is your very first programming language, Raku has something fascinating waiting for you. In this tutorial, we will get Raku installed, write our first program, and explore the different ways to print output. By the end, you will be comfortable running Raku code from both the command line and script files.Installing Raku (Rakudo)
Raku is a language specification. Rakudo is the compiler that implements it. The easiest way to install Rakudo is through rakubrew, which manages Raku installations the way rbenv manages Ruby or nvm manages Node.On macOS or Linux, open a terminal and run:
On macOS you can also use Homebrew:# Install rakubrew (check rakubrew.org for the latest instructions) curl https://rakubrew.org/install-on-perl.sh | bash # Install the latest Rakudo release rakubrew download # Verify the installation raku --version
On Windows, grab the installer from rakudo.org/downloads. The MSI installer sets up your PATH automatically.brew install rakudo
Once installed, confirm everything works:
If you seeraku -e 'say "Raku is ready!"'
Raku is ready! printed to your terminal, you are good to go.
The REPL
Raku ships with an interactive Read-Eval-Print Loop. Just typeraku with no arguments:
The REPL is perfect for trying out small expressions. Every example in this tutorial can be tested there. Note that the REPL automatically prints the result of the last expression, so you do not always need$ raku To exit type 'exit' or '^D' > say "Hello from the REPL!" Hello from the REPL! > 2 + 3 5 > exit
say.
Your First Script
Create a file calledhello.raku with the following content:
Run it from the terminal:say "Hello, World!";
That is it. No boilerplate, no imports, no main function. Raku scripts run top to bottom.$ raku hello.raku Hello, World!
You can also use a shebang line to make scripts executable on Unix-like systems:
Then#!/usr/bin/env raku say "Hello, World!";
chmod +x hello.raku and run it directly with ./hello.raku.
say vs print vs put
Raku gives you three ways to send text to standard output, and each one behaves a little differently.say
say calls the .gist method on its argument and appends a newline. It is designed for human-readable output:
say "Hello"; # Hello (with newline) say 42; # 42 (with newline) say [1, 2, 3]; # [1 2 3] (the .gist of an array)
put
put calls the .Str method on its argument and appends a newline. It is similar to say but gives you the stringified version rather than the gist:
put "Hello"; # Hello (with newline) put 42; # 42 (with newline) put [1, 2, 3]; # 1 2 3 (the .Str of an array, space-separated)
print calls .Str just like put, but does not append a newline:
print "Hello "; print "World"; say ""; # now we add a newline # Output: Hello World
Which one should you use?
For everyday scripting,say is your go-to. Use put when you need the stringified form (especially for data output). Use print when you need precise control over formatting with no automatic newline.
# A practical comparison my @colors = <red green blue>; say @colors; # [red green blue] put @colors; # red green blue print @colors; # red green blue (no trailing newline)
Comments
Raku supports single-line comments with#:
Multi-line comments use# This is a comment say "Hello"; # This is an inline comment
# ... #:
#`(
This is a multi-line comment.
It can span as many lines as you want.
The parentheses can be any paired bracket: (), [], {}, <>
)
say "After the comment";
A Slightly Bigger Example
Let us put a few things together. Here is a script that greets the user:
#!/usr/bin/env raku
# Ask for the user's name
print "What is your name? ";
my $name = get; # read a line from STDIN
# Greet them
say "Hello, $name! Welcome to Raku.";
say "Your name has { $name.chars } characters.";
say "In uppercase: { $name.uc }";
Running this:
$ raku greet.raku
What is your name? Alice
Hello, Alice! Welcome to Raku.
Your name has 5 characters.
In uppercase: ALICE
Notice how Raku interpolates variables ($name) and even code blocks ({ $name.chars }) directly inside double-quoted strings. We will explore this more in later tutorials.
Quick Tips for Getting Started
- File extension: Use
.raku for scripts (older code may use .p6 or .pl6, but .raku is the modern convention).
Semicolons: Statements end with semicolons, except the last statement in a block.
Whitespace: Raku is generally whitespace-flexible, but there are a few places where spaces matter (like between a function name and its parentheses).
Error messages: Raku's error messages are unusually helpful. Read them carefully; they often suggest exactly what went wrong.
What is Next?
Now that you can install Raku, use the REPL, and write simple scripts, you are ready to dive into the language itself. In the next tutorial, we will explore Raku's unique variable system with sigils: the $, @, and %` symbols that tell you what kind of data you are working with.
Happy hacking!