Hello World (first programs) · Beginner · 13 min
Hello World in Clojure: the clj REPL and deps.edn
By Padding · Updated 18 Nov 2026
Debian (clojure:temurin-25-tools-deps image) · Clojure 1.12.7 · Clojure CLI 1.12.7.1681 · Eclipse Temurin JDK 25
You will install the Clojure CLI 1.12.7, print Hello World at the REPL, build a small project with a deps.edn file and a hello.core namespace, and greet a list of names with map.
On this page
Clojure is a Lisp that runs on the Java Virtual Machine (JVM). Your code is a series of lists in parentheses, and each list is a call: the first item is the function, the rest are its arguments. So (+ 1 2) adds one and two, and (println "Hello, World!") prints a line. There are no operators with precedence rules to remember and almost no other syntax.
Two more things make Clojure feel different from most languages you may have seen. Its built-in data structures (lists, vectors, maps and sets) are immutable: adding to a vector gives you a new vector and leaves the old one as it was. And Clojure programmers work inside a running program through the REPL, sending code to it a form at a time, rather than editing, compiling and restarting. Because Clojure compiles each form to JVM bytecode as it loads it, you never run a separate compile step, and you can call any Java library directly.
In this tutorial you install the Clojure CLI, print Hello World at the REPL, set up a small project with a deps.edn file and a namespace with a -main function, then go one step further: write a greet function and use map to greet every name in a vector.
Step 1 · Check that JDK 25 is installed
Clojure is a library that runs on the JVM, so you need a JDK first. If you do not have one, follow the first step of Hello World in Java, which installs Eclipse Temurin JDK 25. Then check it:
java -versionClojure 1.12 needs Java 8 or later, but use a current long-term support JDK such as 25 for new work.
Check it worked
The first line starts with something like openjdk version "25.0.1". Any JDK 25 patch release works.
Step 2 · Install the Clojure CLI
The Clojure CLI gives you two commands. clojure starts Clojure, works out which libraries your project needs, downloads them and runs your code. clj is the same command wrapped in a small tool called rlwrap, which adds line editing and history for typing at the REPL. Install curl and rlwrap, then download the official installer for CLI version 1.12.7.1681 into a fresh temporary folder and run it:
sudo apt update
sudo apt install -y curl rlwrap ca-certificates
cd "$(mktemp -d)"
curl -fL -O https://github.com/clojure/brew-install/releases/download/1.12.7.1681/linux-install.sh
chmod +x linux-install.sh
sudo ./linux-install.sh
cd ~
clojure --versionWhat this does:
rlwrapis only needed byclj. Without it,cljstops withPlease install rlwrap for command editing or use "clojure" instead.cd "$(mktemp -d)"moves into an empty temporary folder, because the installer unpacks its files into the current folder.- The download URL names an exact release, so you get 1.12.7.1681 and not whatever is newest on the day. The script itself downloads the tools archive and checks it against a SHA-256 checksum written into the script before it installs anything.
sudo ./linux-install.shinstallsclojureandcljinto/usr/local/binand the tools into/usr/local/lib/clojure. To install somewhere else, add--prefix <folder>.
The installed CLI gets no apt updates. To upgrade, repeat this step with a newer version number from the Clojure CLI release page at clojure.org.
On macOS, install with Homebrew instead: brew trust clojure/tools once, then brew install clojure/tools/clojure. On Windows, the Clojure team recommends installing WSL (Windows Subsystem for Linux) and following the Linux steps above; a community MSI installer, clj-msi, is the alternative.
Check it worked
clojure --version prints Clojure CLI version 1.12.7.1681. If you see command not found, open a new terminal so your shell finds /usr/local/bin/clojure.
Step 3 · Say Hello World at the REPL
Start the REPL with clj:
cljThe first time, the CLI downloads the Clojure library itself (a few megabytes) into ~/.m2/repository, so do this on Wi-Fi if you are on prepaid mobile data. Later starts reuse that copy. When you see the user=> prompt, type each line and press Enter:
user=> (println "Hello, World!")
Hello, World!
nil
user=> (+ 1 2 3)
6
user=> (str "Hello, " "Amara")
"Hello, Amara"
user=> (clojure-version)
"1.12.7"Look at what comes back:
(println "Hello, World!")printsHello, World!, and then the REPL printsnil. Every expression in Clojure returns a value, andprintlnreturnsnil, Clojure's word for "nothing". The printed line is a side effect;nilis the result.(+ 1 2 3)shows prefix notation:+comes first, then any number of arguments. You write one+for three numbers.strjoins values into one string. The REPL shows the result in double quotes because it prints values the way you would type them back in.(clojure-version)shows which Clojure the REPL is running. With no project, the CLI uses its default, and a CLI version number starts with that default: CLI 1.12.7.1681 runs Clojure 1.12.7. In a later step you pin the version in your project, so it stays put when you upgrade the CLI.
Press Ctrl+D to leave the REPL.
You can also evaluate one expression straight from your shell with -e, which is handy for quick checks:
clojure -M -e '(println "Hello, World!")'-M tells the CLI to run Clojure's main entry point, and -e passes it an expression to evaluate. With -e, Clojure prints a result only when it is not nil, so you see the greeting and nothing else.
Check it worked
At the REPL, (println "Hello, World!") printed Hello, World! followed by nil, and the clojure -M -e command printed Hello, World! on its own.
Step 4 · Create a project with deps.edn and a namespace
A Clojure project is a folder with a deps.edn file at the top and source files under src. Make a throwaway folder and the project files:
mkdir -p ~/hello-clojure-demo/src/hello
cd ~/hello-clojure-demo
cat > deps.edn <<'EDN'
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.12.7"}}}
EDN
cat > src/hello/core.clj <<'CLJ'
(ns hello.core)
(defn -main [& args]
(println "Hello, World!"))
CLJYou can also create the two files in your editor. Start with deps.edn. It is written in EDN, Clojure's data format, so it is a Clojure map: keys and values inside curly braces.
:paths ["src"]tells the CLI that your source code lives in thesrcfolder. Words starting with a colon are keywords, Clojure's usual map keys, and["src"]is a vector with one string in it.:depslists the libraries the project needs. Here there is one: the Clojure language itself,org.clojure/clojure, at exactly version 1.12.7 from Maven, the same package repository Java projects use. Pinning it here means everyone who runs the project gets the same Clojure.
Now src/hello/core.clj, line by line:
(ns hello.core)declares the namespacehello.core. A namespace is a named group of functions, like a module. The name maps to the file path:hello.corelives inhello/core.cljundersrc.(defn -main [& args]defines a function called-main.defnmeans "define a function", the name comes next, and the vector after it lists the parameters.& argscollects any command-line arguments into one sequence calledargs. The leading dash in-mainis a convention Clojure uses for a namespace's entry point.(println "Hello, World!"))is the body. The last value in a function is what it returns, so there is noreturnkeyword. The two closing parentheses end theprintlncall and thedefn.
Run it:
clojure -M -m hello.core-m hello.core tells Clojure to load the namespace hello.core and call its -main function. Clojure reads the file, compiles each form to bytecode in memory and runs it. clj -M -m hello.core does exactly the same; clojure is the usual choice for running programs because you will not be typing into them.
Your deps.edn asks for Clojure 1.12.7, which is also the CLI's default, so you cannot tell the pin is working yet. To see that the version comes from the project's dependencies, check it, then ask for a different one, 1.12.6, for a single run with -Sdeps, which adds extra dependencies on top of deps.edn without editing it:
clojure -M -e '(println (clojure-version))'
clojure -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.12.6"}}}' -M -e '(println (clojure-version))'The first prints 1.12.7, from your deps.edn. The second prints 1.12.6: the dependency list decides which Clojure runs, not the CLI. That is what the pin buys you. When you later upgrade the CLI and its default moves on, this project keeps running 1.12.7 until you change deps.edn. The second command downloads Clojure 1.12.6 once (a few megabytes); skip it if data is tight.
The CLI also creates a hidden .cpcache folder in the project. It caches the list of library files the project needs, so later runs start faster. You can delete it at any time.
Check it worked
clojure -M -m hello.core prints Hello, World!, and the two version checks print 1.12.7 and then 1.12.6. Run ls -a and you see deps.edn, src and .cpcache.
Step 5 · Write a greet function and map it over names
Now make the program do something with data. Replace src/hello/core.clj:
cat > src/hello/core.clj <<'CLJ'
(ns hello.core)
(defn greet [name]
(str "Hello, " name "!"))
(defn -main [& args]
(let [names (if (seq args) args ["Amara" "Kofi" "Wanjiru"])]
(doseq [line (map greet names)]
(println line))))
CLJ
clojure -M -m hello.core
clojure -M -m hello.core Ngozi ThaboLine by line:
(defn greet [name] (str "Hello, " name "!"))defines a function that takes one name and returns a greeting string. It prints nothing; it only returns a value, which makes it easy to test and reuse.(let [names ...] ...)gives a local name to a value. Insidelet,namesmeans whatever follows it.(if (seq args) args ["Amara" "Kofi" "Wanjiru"])chooses that value.(seq args)isnilwhen there are no arguments, andnilcounts as false, so with no arguments you get the vector of three names. Square brackets make a vector, an ordered collection.(map greet names)callsgreeton each name and gives back a sequence of greetings. You pass the function itself tomap, which is normal in Clojure: functions are values like any other.(doseq [line ...] (println line))walks through that sequence and prints each item. Usedoseqwhen you want a side effect, such as printing, for every item.
Names in Clojure can contain dashes and even ? or !, which is why you will see functions like empty?. Names with accents or tone marks, such as "Adéọlá" or "Zoë", work as they are, because Clojure strings are Java strings and hold any Unicode text.
Check it worked
The first run prints Hello, Amara!, Hello, Kofi! and Hello, Wanjiru! on three lines. The second prints Hello, Ngozi! and Hello, Thabo!, because the command-line arguments replaced the default names.
Step 6 · See immutable data for yourself
In many languages, adding an item to a list changes that list. In Clojure, conj (short for "conjoin") returns a new collection and leaves the original alone. Try it from the project folder:
clojure -M -e '(let [names ["Amara" "Kofi"] more (conj names "Zara")] (prn names) (prn more))'What happens:
(conj names "Zara")builds a new vector with"Zara"on the end and binds it tomore.namesstill holds the original two names.prnprints values the way you would type them, with the quotes around strings, so you can see exactly what each vector holds.
This does not copy the whole vector each time. Clojure's collections share structure internally, so the new vector reuses most of the old one. Because nothing can change a value once it exists, you can pass data between functions and threads without worrying that something else will modify it.
Check it worked
The command prints ["Amara" "Kofi"] and then ["Amara" "Kofi" "Zara"].
Step 7 · Fix the mistakes beginners hit and clean up
These come up early. Each has a known cause:
Please install rlwrap for command editing or use "clojure" instead.: you rancljwithout rlwrap installed. Install it withsudo apt install rlwrap, or useclojure.Could not locate hello/core__init.class, hello/core.clj or hello/core.cljc on classpath: the namespace name and the file path do not match, or you ran the command outside the project folder.hello.coremust be insrc/hello/core.clj. A dash in a namespace becomes an underscore in the file name:hello.my-applives insrc/hello/my_app.clj.EOF while reading: a parenthesis, bracket or brace is not closed. Count them, or use an editor with Clojure support that matches pairs for you.ClassCastException ... cannot be cast to class clojure.lang.IFn: you put something that is not a function first in a list, for example("Amara" "Kofi"). Use a vector,["Amara" "Kofi"], for data.- Nothing prints from
(map println names)inside a function:mapis lazy. It only does its work when something asks for the results, and if nothing does,printlnnever runs. At the REPL it seems to work because the REPL prints the result and so asks for it. Usedoseqfor side effects, as in the greet step. - Single quotes for text:
'Amara'is not a string in Clojure. Strings always use double quotes.
Clean up when you are done. This removes only the folder you made:
cd ~
rm -rf ~/hello-clojure-demoTo remove the Clojure CLI as well, delete /usr/local/bin/clojure, /usr/local/bin/clj and the /usr/local/lib/clojure folder with sudo rm. Downloaded libraries sit in ~/.m2/repository; Java tools such as Maven share that folder, so keep it if you use them.
Check it worked
ls ~/hello-clojure-demo reports that there is no such file or directory, and clojure --version still works if you kept the CLI.
Where Clojure is used
Clojure is most at home in backend services that move and transform a lot of data, where immutable maps and vectors make the code easier to reason about. Nubank, the Brazilian digital bank, runs much of its platform on Clojure and in 2020 acquired Cognitect, the company that stewards the language. Other teams use it for financial systems, data pipelines and internal tools, often next to Java services because it shares the JVM and its libraries. ClojureScript, a sibling that compiles to JavaScript, takes the same language to the browser. For larger projects you add libraries under :deps and aliases in deps.edn, or use Leiningen, an older build tool you will still meet in many projects.
Next steps
- Compare Clojure with another Lisp that has its own long history and a standard: Hello World in Common Lisp.
- Try a Lisp designed for teaching and for building languages: Hello World in Racket.
- See the JVM, bytecode and JDK from the Java side: Hello World in Java.
Related tutorials
- Hello World in Zig: zig run, zig build and zig ccYou will install a signature-checked Zig 0.17.1 on Ubuntu 26.04, write and run Hello World with the current I/O API, build a small project with zig build that handles errors explicitly, and use zig cc to compile a C program for Linux and for Windows.
- Hello World in x86-64 assembly with NASM and Linux system callsYou will write an x86-64 assembly program that prints a line using only Linux system calls, assemble it with NASM, link it with ld, check its exit status, then loop it three times and read its machine code with objdump.
- Hello World in WebAssembly text format with wabt and WasmtimeYou will write a WebAssembly module by hand in the text format, assemble it with wat2wasm, print Hello World through WASI in Wasmtime 50, and call an exported add function from both Wasmtime and Node.js.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials