Initial Setup
Get Clojure installed and running your first program. This guide walks you through installation on any operating system and gets you writing code immediately.
π― What You’ll Accomplish
By the end of this tutorial, you’ll have:
- β Clojure and Leiningen installed and verified
- β Your first Clojure program running
- β A working REPL for interactive development
π Prerequisites
- Java Development Kit (JDK) 8 or later
- Basic familiarity with your computer’s terminal/command line
- No prior Clojure experience required
πΎ Step 1: Install Java
Clojure runs on the Java Virtual Machine (JVM), so you need Java installed first.
Verify Java Installation
java -versionIf Java is installed, you’ll see version information. If not, install it:
Install Java
Windows/macOS/Linux: Download from Adoptium (formerly AdoptOpenJDK):
- Visit adoptium.net
- Download Temurin JDK 17 or later (LTS version recommended)
- Run the installer
- Verify:
java -version
macOS (Homebrew):
brew install openjdk@17Linux (Ubuntu/Debian):
sudo apt update
sudo apt install openjdk-17-jdkπΎ Step 2: Install Clojure CLI Tools
Windows
Using Scoop:
scoop install clojureOr download the installer from clojure.org.
macOS
Using Homebrew:
brew install clojure/tools/clojureLinux
curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh
chmod +x linux-install.sh
sudo ./linux-install.shVerify Installation
clojure --versionExpected output:
Clojure CLI version 1.11.x.xπΎ Step 3: Install Leiningen (Build Tool)
Leiningen is the most popular Clojure build tool for managing dependencies and projects.
Windows
Download lein.bat and place it in a directory on your PATH.
macOS/Linux
curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > ~/bin/lein
chmod +x ~/bin/lein
leinThe first run will download dependencies.
Verify Installation
lein versionExpected output:
Leiningen 2.x.x on Java x.x.xπ Step 4: Create Your First Clojure Program
Using REPL (Interactive Shell)
clojureYou’ll see the Clojure REPL prompt:
user=>Try some commands:
user=> (println "Hello, Clojure!")
Hello, Clojure!
nil
user=> (+ 1 2 3)
6
user=> (def name "Alice")
#'user/name
user=> (str "Hello, " name "!")
"Hello, Alice!"
user=> (exit)Type (exit) or press Ctrl+D to exit the REPL.
Create a Project with Leiningen
lein new app hello-clojure
cd hello-clojureThis creates a new project structure:
hello-clojure/
βββ project.clj # Project configuration
βββ src/
β βββ hello_clojure/
β βββ core.clj # Main source file
βββ test/
βββ hello_clojure/
βββ core_test.cljEdit the Main File
Open src/hello_clojure/core.clj:
(ns hello-clojure.core
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, Clojure World!"))Run Your Program
lein runExpected output:
Hello, Clojure World!β Verification Checklist
Before moving forward, verify:
-
java -versionshows Java 8 or later -
clojure --versionshows Clojure CLI installed -
lein versionshows Leiningen installed - REPL starts with
clojurecommand -
lein runexecutes your hello-clojure project
π You’re Done!
You’ve successfully installed Clojure and run your first program. You’re ready for the next step.
π What’s Next?
Quick learner: Clojure Quick Start
- Learn core syntax and basic patterns in one session
- Understand enough to explore Clojure independently
Code-first learner: Clojure By Example
80 annotated, runnable examples covering 95% of production Clojure
Best for experienced developers who prefer learning through code
Progressive learning path from beginner to advanced
Deep understanding of Clojure’s philosophy and patterns
π Troubleshooting
Java Issues
Problem: “java: command not found”
Solution: Verify Java is installed and in your PATH. Restart terminal after installation.
Clojure CLI Issues
Problem: “clojure: command not found”
Solution: Verify installation completed successfully. On macOS, ensure /usr/local/bin is in your PATH.
Leiningen Issues
Problem: “lein: command not found”
Solution: Verify lein script is in a directory on your PATH. On macOS/Linux, ensure ~/bin is in PATH.
Problem: “Could not find or load main class clojure.main”
Solution: Run lein by itself to download dependencies first.