27.08.2024
How to install and setup clojure on windows
Clojure is a Lisp language built on the JVM. Lisp languages are a natural way to manipulate and generate HTML, because HTML's node structure is a tree, which can be represented as nested linked lists. I enjoy using Clojure for web development and sometimes I use Windows 11.
Java
Clojure requires Java, so install that first. I use microsoft's OpenJDK 21 build: https://learn.microsoft.com/en-ca/java/openjdk/download#openjdk-21
Clojure is compatible with Java 8 and above. Java 21 is the most recent long term service version.
Deps.clj
For the Clojure command line tool I use the deps.clj version on windows.
Start Windows PowerShell with Run as Administrator:
C:\Temp> PowerShell -Command "irm https://raw.githubusercontent.com/borkdude/deps.clj/master/install.ps1" > install_clojure.ps1
C:\Temp> PowerShell -ExecutionPolicy Bypass -File install_clojure.ps1 --as-clj
Restart the command prompt:
C:\Temp> clj
Downloading https://github.com/clojure/brew-install/releases/download/1.12.3.1577/clojure-tools.zip to C:\Users\hahah\.deps.clj\1.12.3.1577\ClojureTools\clojure-tools.zip
Unzipping C:\Users\hahah\.deps.clj\1.12.3.1577\ClojureTools\clojure-tools.zip ...
Successfully installed clojure tools!
Downloading: org/clojure/clojure/1.12.3/clojure-1.12.3.pom from central
Downloading: org/clojure/clojure/1.12.3/clojure-1.12.3.jar from central
Clojure 1.12.3
user=>
Leiningen
I use Leiningen for clojure project configuration.
Download this leiningen.bat script into a folder that is in your environment variable path.
In command line:
C:\Users\me\Downloads> lein self-install
Downloading Leiningen now...
The script will install the Leiningen jar file into C:\Users\me\.lein\self-installs
Lein Ancient
lein-ancient is a tool to check and update packages for leiningen projects
In ~/.lein/profiles.clj
{:user {:plugins [[lein-ancient "1.0.0-RC3"]]}}
then in your project folder you can type:
lein ancient
Babashka
babashka is a clojure interpreter that can be used to run clojure scripts or to start a repl without a project in VSCode.
I install babashka by downloading the binary and putting it into a folder that is in my environment variables. I download the release here: https://github.com/babashka/babashka/releases
Click Show all 18 assets to see the windows executable.
I am on a x86_64 machine, so I use babashka-1.3.191-windows-amd64.zip. I unzip that and put the binary in C:\Users\me\tools
VSCode and Calva
I prefer using Emacs to write clojure code, but I have found Emacs slower on windows and it was challenging to install. The speed is better on Windows Subsystem Linux, but I had an issue where I wasn't able to open the Emacs window and the only fix I found was to reinstall the linux subsystem.
VSCode with the Calva extension is pretty good and it's easy to setup. Download and install VSCode, then go to Extensions (Ctrl+Shift+X) and search for Calva and click Install.