Getting Started with Clojure on Windows

I’ve been taking a break from writing blog posts because I’ve been feeling pretty burned out the past few months, but I’m trying to get back to functional programming following my experiences at Strange Loop 2018.

I heard a lot of good things about Clojure at Strange Loop, so I’m going to start learning the language. In this post I’ll be discussing how to get Clojure working on Windows because developing for the language is only officially supported on Linux and Mac.

I’m also going to discuss how to get Clojure working on Windows Subsystem for Linux (WSL).

Clojure on Windows

If you don’t have Windows Powershell, I recommend getting that first. It’s generally a better than the Windows Command Line.

Also, you need to install Java with a version greater than 1.6 because Clojure runs on the JVM. You can check your Java version with the following command:

java -version

Getting Leiningen

In order to install Clojure on Windows, you must first install Leiningen. I tried using the lein script on the Leiningen website, but it didn’t work for me at the time of writing. Instead, I used Chocolatey to perform the installation. (More information can be found about this at https://chocolatey.org/packages/lein)

First, run Powershell as administrator by right clicking on the Powershell icon and run the following command to install Chocolatey:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Then run the Leiningen installation using Chocolatey:

choco install lein

It’s possible that the Leiningen installation may fail, in which case you can try running:

lein self-install

When I tried this on my machine, the self installer failed to download the Leiningen jar file. If this happens to you, you can download the latest jar file here: https://github.com/technomancy/leiningen/releases

Rename the standalone .zip file extension to .jar and place it in your %HOME%/.lein/self-installs/ directory.

After restarting the Powershell, you should be able to run the following command to create a Clojure project:

lein new app my-app

You can run the app by changing to the app directory and calling:

lein run

You can run a REPL using the following command:

lein repl

You can find more information about working with Leiningen here: https://www.braveclojure.com/getting-started/

Clojure on WSL

Getting Windows Subsystem for Linux (WSL)

WSL is a convenient way to cross compile for Linux if you have a Windows 10 machine.

You can find instructions for installing WSL here: https://docs.microsoft.com/en-us/windows/wsl/install-win10

Once you’ve restarted your computer, you can install Ubuntu 18.04 LTS by searching in Windows Store for Ubuntu:

UbuntuWSL

Getting Clojure on WSL

Check your Java version with:

java -version

You should have a Java version greater than 1.6 to run Clojure.

Once you’ve installed Ubuntu 18.04 LTS on WSL, you can run the following command to install Leiningen:

sudo apt-get install leiningen

and you’re ready to get started with Clojure development!

References

https://clojure.org/

https://leiningen.org/

https://chocolatey.org/

https://www.braveclojure.com/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s