It's been a bit quiet in here lately so I thought I would drop some news about an easier process to get started with Clojure!
For a while now, the Clojure/core team at Cognitect have been working on improving the "entry" process for using Clojure. In the past, you either downloaded the JAR and ran that directly at the terminal -- which was a very bare bones experience -- or you installed one of the Clojure build tools (Leiningen or Boot) in order to get a REPL up and running, or run your program or your tests. Recently, a new command-line tool has been made available and the Getting Started
section on Clojure's web site has been updated.
If you're on a Mac, it's as simple as brew install clojure
which will install both a basic clojure
command and a more friendly clj
command (that uses rlwrap
to provide history and editing at the terminal).
If you're on Linux, you can use curl
to download an installation script but packaged versions are coming (for apt-get
If you're on Windows, a PowerShell installer is in the works (but, hey, if you're on Windows 10, you can install Ubuntu etc via Windows Subsystem for Linux and use the Linux installer script -- and that works just fine).
The new command line tool starts a REPL by default but can also fetch library dependencies and add them to the classpath. It can also run your code, providing options to specify the "main" function and arguments to that, as well as JVM options.
Dependencies are specified in a file called deps.edn
(EDN is an enhanced form of JSON). You can specify libraries on Maven Central or Clojars (the Clojure community's Maven-compatible repository -- for arbitrary Clojure projects). You can also specify dependencies as Git coordinates (a URL to the source code repository and the SHA to identify the commit to use) or on the local file system (so you can manage multiple projects locally that depend on each other).
The command line tools introduce the concept of aliases (somewhat borrowed from Leiningen) that let you layer and combine dependencies and options in ways that are very powerful. Here's my .clojure/deps.edn
file with several useful aliases for running tests, benchmarking, measuring memory usage, starting various types of REPL, choosing which version of Clojure to use etc.