LinuxCommandLibrary

clj

Run Clojure programs or start a REPL

TLDR

Start a REPL (interactive shell)

$ clj
copy

Execute a function
$ clj -X [namespace/function_name]
copy

Run the main function of a specified namespace
$ clj -M [[-m|--main]] [namespace] [args]
copy

Prepare a project by resolving dependencies, downloading libraries, and making/caching classpaths
$ clj -P
copy

Start an nREPL server with the CIDER middleware
$ clj -Sdeps '{:deps {nrepl {:mvn/version "0.7.0"} cider/cider-nrepl {:mvn/version "0.25.2"]}' [[-m|--main]] nrepl.cmdline --middleware '["cider.nrepl/cider-middleware"]' --interactive
copy

Start a REPL for ClojureScript and open a web browser
$ clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.758"]}' [[-m|--main]] cljs.main [[-r|--repl]]
copy

SYNOPSIS

clj [options] [script-or-expression]

PARAMETERS

-A, --aliases <aliases>
    Merge given aliases into deps.edn for classpath

-J<flag>
    Pass JVM flag through to Java calls

-M, --main <alias>
    Merge main alias and execute its :main-opts

-R, --resolve-aliases <aliases>
    Merge aliases for runtime classpath only

-Sdeps <deps-edn>
    Use specified deps.edn file

-Serr
    Print full deps exceptions

-Sforce
    Force re-download of all dependencies

-Spath
    Print computed classpath

-Spoll
    Poll Clojars/Maven for latest versions

-Srepro
    Use reproducible classpath options

-Sthreads
    Use parallel threads for dependency resolution

-Sverbose
    Verbose output for deps processing

-T<tool>
    Run tooling alias (e.g., -T:build)

-X<exec-fn>
    Execute function from exec alias

-r, --repl
    Start interactive REPL

DESCRIPTION

The clj command is the official command-line interface for Clojure, a functional Lisp dialect on the JVM. It enables running Clojure scripts, launching interactive REPLs, managing dependencies via deps.edn, and executing tasks with aliases. Designed for simplicity, clj supports reproducible builds, JVM customization, and integration with editors like VS Code or Emacs.

Key features include automatic dependency resolution from Maven/Clojars, runtime classpath computation, and support for multi-module projects. Use it standalone for scripts (clj script.clj) or with -M:alias for configured mains. It downloads the Clojure JAR on first run and caches deps.edn configurations.

Ideal for prototyping, automation, and development, clj replaced older tools like Leiningen for CLI usage while maintaining compatibility. Requires Java 8+ and respects $CLJ_OPTS env var for global options.

CAVEATS

Requires Java 8+; first run downloads Clojure tools (~40MB). Not for production deploys—use uberjars. Env vars like CLJ_OPTS override options.

EXAMPLES

clj -r # REPL
clj -M:run script.clj # Run with alias
clj -Spath -Sdeps project/deps.edn # Classpath

HISTORY

Introduced in 2018 with Clojure 1.10 CLI tools by Clojure/core team to simplify deps and REPLs, evolving from bootstrapped clojure script. Now at version 1.11+.

SEE ALSO

clojure(1), bb(1), lein(1), java(1)

Copied to clipboard