Skip to main content

Hello World (first programs) · Beginner · 13 min

Hello World in Racket: #lang, DrRacket and raco

By Padding · Updated 18 Nov 2026
Debian (racket/racket:9.3 image) · Racket 9.3 (Racket CS)

You will install Racket 9.3, run a Hello World module from the terminal and in DrRacket, compile it with raco make, and turn a greeting program that reads a name from the command line into an executable with raco exe.

On this page

Racket started life as PLT Scheme, a member of the Lisp family, and was renamed in 2010 when it had grown into something more than a Scheme. Like every Lisp, a program is made of parenthesised lists where the first item is the function and the rest are its arguments: (+ 1 2) adds two numbers, and (displayln "Hello, World!") prints a line.

What sets Racket apart is the first line of every file. #lang racket is not a comment or a version marker: it tells Racket which language the rest of the file is written in. Racket ships with many such languages, from a smaller racket/base to the student languages used by the textbook How to Design Programs, and you can write your own. That is why Racket describes itself as a language for making languages.

Since version 8.0, the standard Racket runs on top of Chez Scheme, a fast Scheme compiler, and compiles your code to machine code before running it. In this tutorial you install Racket 9.3, write and run Hello World, open it in DrRacket (the editor that comes with Racket), compile it with raco make, and then go one step further: a greet function that reads a name from the command line, built into a program you run without typing racket.

Step 1 · Install Racket 9.3

Racket's own installers are the simplest route on every platform, and they always have the current release. Ubuntu's racket package can lag behind, so use the installer here even on Ubuntu.

On Linux, download the installer for your processor and its checksum from the 9.3 release, check it, then install Racket into a folder in your home directory. The full installer is about 260 MB. If you are on prepaid mobile data, download it on Wi-Fi, or see the note on Minimal Racket below.

Bash
cd "$(mktemp -d)"
case "$(uname -m)" in
  x86_64) FILE=racket-9.3-x86_64-linux-buster-cs.sh; SUM=30dc59d9b5af083eacf793253d35782c5231e8bfb7a7331fe32ccd9a41fd792f ;;
  aarch64) FILE=racket-9.3-aarch64-linux-buster-cs.sh; SUM=26e4d1c3bf8954c4413fb6737af5d211d44c1e158e34e4c90e0af1cde6353c9a ;;
  *) echo "Unsupported processor: $(uname -m)"; false ;;
esac
curl -fL -O "https://download.racket-lang.org/releases/9.3/installers/${FILE}"
echo "${SUM}  ${FILE}" | sha256sum -c
sh "${FILE}" --in-place --dest ~/racket-9.3
echo 'export PATH="$HOME/racket-9.3/bin:$PATH"' >> ~/.bashrc
export PATH="$HOME/racket-9.3/bin:$PATH"
racket --version

What each part does:

  • The case block picks the right file for an Intel/AMD (x86_64) or ARM (aarch64) machine, and the SHA-256 value published on the 9.3 release page for that file.
  • sha256sum -c must print OK. If it prints FAILED, delete the file and download it again before going further.
  • --in-place --dest ~/racket-9.3 answers the installer's questions for you: keep the whole of Racket in one folder, and put that folder at ~/racket-9.3. Without these flags the installer asks whether you want a "Unix-style" install spread across /usr and where to put it. A single folder is easy to delete and lets you keep two versions side by side.
  • The two PATH lines make racket, raco and drracket findable now and in every new terminal.

A Racket installed this way gets no apt updates. To upgrade, repeat this step with the next version number and its checksum from download.racket-lang.org.

On macOS, download the .dmg for Apple Silicon or Intel from download.racket-lang.org, open it and drag the Racket v9.3 folder into Applications. On Windows, run the .exe installer; it adds DrRacket to the Start menu. On both, DrRacket is the program to open, and the racket and raco commands are inside the installed folder.

Minimal Racket. The same release page offers a Minimal Racket installer of about 36 MB. It has the language and the raco pkg package tool but not DrRacket or the documentation. It is a good choice for a server or a slow connection; you add pieces later with raco pkg install. This tutorial assumes the full install.

Check it worked

racket --version prints something like Welcome to Racket v9.3 [cs]. The [cs] means the Chez Scheme based Racket, which is the default.

Step 2 · Write and run Hello World

Make a throwaway folder and the file hello.rkt. You can type the two lines into your editor instead of using cat:

Bash
mkdir -p ~/hello-racket-demo
cd ~/hello-racket-demo
cat > hello.rkt <<'RKT'
#lang racket

(displayln "Hello, World!")
RKT
racket hello.rkt

Line by line:

  • #lang racket says this file is a module written in the racket language. Every Racket source file starts with a #lang line, and it must be the first line. The racket language includes lists, strings, files, networking and much more, ready to use without any imports.
  • The blank line is only for readability.
  • (displayln "Hello, World!") calls the function displayln with one argument, a string. displayln writes the value for a person to read, without quotes, and ends the line. Its sibling display does the same without the newline.

racket hello.rkt loads the module, compiles it to machine code in memory and runs it from top to bottom.

Check it worked

The terminal prints Hello, World! on its own line, with no quote marks.

Step 3 · Try the REPL and see what a module prints

Run racket with no file and you get a REPL, a prompt where each expression is read, evaluated and its result printed:

Bash
racket

Type these one at a time after the > prompt:

Text
> (displayln "Hello, World!")
Hello, World!
> (+ 1 2 3)
6
> (string-append "Hello, " "Amara")
"Hello, Amara"
> (string-upcase "sannu")
"SANNU"

displayln prints the greeting and returns nothing worth showing, so the REPL prints nothing more. The other three return a value, which the REPL prints in the form you would type it back in, so strings appear with quotes. (+ 1 2 3) shows prefix notation: one + for any number of arguments. Press Ctrl+D to leave.

A #lang racket module behaves a little like the REPL: any expression at the top level of the file that produces a value, other than "void", has that value printed when the module runs. Try it:

Bash
cat > values.rkt <<'RKT'
#lang racket

(displayln "Some results:")
(+ 1 2 3)
(string-append "Hello, " "Amara")
(define unused 42)
RKT
racket values.rkt

(define unused 42) gives a name to a value and prints nothing, because a definition is not an expression with a result. In a real program you print on purpose with displayln and keep bare expressions out of the top level, but this behaviour makes small experiments quick.

Check it worked

At the REPL, (+ 1 2 3) showed 6. racket values.rkt printed three lines: Some results:, 6 and "Hello, Amara" with its quotes. The define added no output.

Step 4 · Open the file in DrRacket

DrRacket is the editor that comes with the full install, built for Racket and for learning. Open it from your applications menu, or from a terminal on your desktop:

Bash
drracket ~/hello-racket-demo/hello.rkt &

The window has two parts:

  • The top half, the definitions area, shows your file. Edit it here and save with Ctrl+S (Cmd+S on a Mac).
  • Click Run at the top right (or press Ctrl+R, Cmd+R on a Mac). The bottom half, the interactions area, prints Hello, World! and then gives you a > prompt, a REPL that can see everything your file defines.

DrRacket reads the #lang line to know which language the file uses, so the same file runs the same way in DrRacket and in the terminal. As you type, it highlights the matching parenthesis for the one beside the cursor, which saves beginners a lot of counting. If you follow How to Design Programs, the book's student languages, such as Beginning Student, are under Language > Choose Language in DrRacket; they give simpler error messages and fewer features on purpose.

Check it worked

After you click Run, the interactions area shows Hello, World!. Type (+ 2 2) at its > prompt and press Enter; it shows 4.

Step 5 · Compile ahead of time with raco make

raco is Racket's command-line tool: one command with sub-commands for packages, compiling, building executables and documentation. raco make compiles a module and saves the result, so the next run does not compile it again:

Bash
raco make -v hello.rkt
find compiled -type f
racket hello.rkt
  • raco make -v hello.rkt compiles hello.rkt and any modules it depends on in your folder. -v makes it say what it is doing.
  • The compiled code goes into a compiled folder next to the source, in a file ending .zo.
  • racket hello.rkt notices the up-to-date .zo file and loads it instead of compiling the source. If you edit hello.rkt, the saved code is out of date, and Racket compiles from source again until you rerun raco make.

For a two-line file the difference is tiny. For a program made of many modules it saves real start-up time. The compiled folder can be deleted at any time; leave it out of version control.

Check it worked

find lists a file ending in hello_rkt.zo under compiled, and racket hello.rkt still prints Hello, World!.

Step 6 · Greet a name from the command line

Now make a program that does something with input. Create greet.rkt:

Bash
cat > greet.rkt <<'RKT'
#lang racket

(define (greet name)
  (string-append "Hello, " name "!"))

(define args (current-command-line-arguments))

(define name
  (if (> (vector-length args) 0)
      (vector-ref args 0)
      "World"))

(displayln (greet name))
RKT
racket greet.rkt
racket greet.rkt Adéọlá

Line by line:

  • (define (greet name) ...) defines a function called greet with one parameter, name. The parentheses around greet name are what make this a function rather than a plain value.
  • (string-append "Hello, " name "!") joins three strings into one. It is the last expression in the function, so it is the value the function returns. Racket has no return keyword.
  • (current-command-line-arguments) gives you the words typed after the file name, as a vector (a fixed-size array) of strings. Racket's own flags are not included, so for racket greet.rkt Adéọlá the vector holds one string, "Adéọlá".
  • (if test then else) picks one of two values. When the vector is not empty, (vector-ref args 0) takes its first item (counting starts at 0); otherwise the name is "World".
  • (displayln (greet name)) calls greet and prints what it returns. greet itself prints nothing, which makes it easy to reuse and test.

Racket strings are Unicode, so names with accents and tone marks, such as Adéọlá, Zoë or Nnamdi, work as typed, as long as your terminal uses UTF-8 (most do).

Check it worked

The first run prints Hello, World!. The second prints Hello, Adéọlá!.

Step 7 · Build an executable with raco exe

raco exe wraps a module and the parts of Racket it needs into a program you can run directly:

Bash
raco exe greet.rkt
./greet Kwame

On Linux this creates a file called greet (on Windows greet.exe, on a Mac greet.app for GUI programs or greet otherwise). The arguments reach current-command-line-arguments the same way as before.

The executable starts without you typing racket, but it can still depend on Racket's shared libraries and files on this computer. To give the program to someone without Racket installed, package it with raco distribute, which collects everything it needs into one folder:

Bash
raco distribute greet-dist greet
./greet-dist/bin/greet Wanjiru

Check it worked

./greet Kwame prints Hello, Kwame!, and ./greet-dist/bin/greet Wanjiru prints Hello, Wanjiru!. ls greet-dist shows a bin folder and a lib folder.

Step 8 · Fix the mistakes beginners hit and clean up

These errors come up early, each with a known cause:

  • racket: command not found: the bin folder of your Racket install is not on your PATH. Open a new terminal, or run the export PATH=... line from the install step again.
  • An error saying it expected a module declaration, or no #lang: the file has no #lang racket line, or something comes before it. It must be the very first line.
  • read-syntax: expected a ')' to close '(' (or similar): a parenthesis is not closed. DrRacket's highlighting shows which ones match.
  • application: not a procedure: something that is not a function came first in a pair of parentheses, for example ("Amara") or an extra pair around a value such as ((greet "Amara")). In Racket, parentheses always mean "call this".
  • string-append: contract violation with expected: string?: you passed a number where a string is needed, such as (string-append "Age: " 30). Convert it first with (number->string 30).
  • Single quotes for text: 'Amara' is not a string. Strings use double quotes; a single quote in Racket means something else (a quoted symbol or list).

When you are done, delete the demo folder. This removes only what you made here:

Bash
cd ~
rm -rf ~/hello-racket-demo

To remove Racket too, delete ~/racket-9.3 and the export PATH line you added to ~/.bashrc. Packages you install with raco pkg install go under your home directory in ~/.local/share/racket; delete that folder as well if you want nothing left.

Check it worked

ls ~/hello-racket-demo reports No such file or directory, and racket --version still works if you kept Racket.

Where Racket is used

Racket's main home is teaching: How to Design Programs and its DrRacket student languages are used in introductory courses at universities around the world, because the languages grow with the student and the error messages are written for beginners. It is also a research language for people who study programming languages, and a practical tool for building small languages of your own. Racket's documentation is written in Scribble, a Racket language for documents, and the Pollen book publishing system is built the same way. For general programs, the standard library covers web servers, databases and GUIs, and raco pkg installs more from pkgs.racket-lang.org.

Next steps

Need this done for you?

Padding does this work for growing companies, from the first diagnosis to a system that keeps working.

Platform Engineering

Get new tutorials

New tutorials, about twice a month.