Installation, Tooling and the REPL
2.1 Installing
Leiningen (lein) is the older, still widely used build tool (project.clj). Babashka (bb) runs Clojure scripts instantly without the JVM.
# Prerequisite: a JDK (17 or 21 LTS recommended)
java -version
# macOS / Linux (Homebrew)
brew install clojure/tools/clojure
# Linux (official script)
curl -L -O https://github.com/clojure/brew-install/releases/latest/download/linux-install.sh
chmod +x linux-install.sh && sudo ./linux-install.sh
# Windows: use the clj-msi installer, Scoop (scoop install clojure), or WSL
clj # start a REPL (with rlwrap line editing)
clojure -M -e '(println "Hello")' # evaluate an expression2.2 Editors
Calva (REPL, inline evaluation, paredit, clj-kondo linting) CIDER + clojure-mode + paredit Conjure, vim-fireplace, vim-iced
Clover (VS Code), nightcode, Portal (data visualization), Morse (inspector)
2.3 Your First Project
Project generators: deps-new (clojure -Tnew app :name myname/myapp), neil (Babashka-based project helper), and lein new app myapp.
mkdir -p hello/src/hello && cd hello
cat > deps.edn <<'EOF'
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.12.0"}}}
EOF
cat > src/hello/core.clj <<'EOF'
(ns hello.core)
(defn greet [name]
(str "Hello, " name "!"))
(defn -main [& args]
(println (greet (or (first args) "World"))))
EOF
clj -M -m hello.core Clojure # Hello, Clojure!2.4 The REPL
Clojure 1.12 can add libraries to a running REPL: (add-lib 'org.clojure/data.json).
user=> (+ 1 2)
3
user=> (doc map) ; documentation
user=> (source when) ; view source
user=> (apropos "split") ; search
user=> (find-doc "reduce")
user=> *1 ; last result (*2, *3 earlier ones)
user=> *e ; last exception
user=> (require '[clojure.string :as str])
user=> (str/upper-case "hi")
"HI"
user=> (dir clojure.string) ; list a namespace's public vars