Clojure Tutorial - Installing and Testing Required Dependencies
In this chapter, we'll setup our system to run Clojure. We'll install all the required dependencies and run the "Hello World" program.
👩💻 Download the complete set of code for this course here
🎳 Join us over at the
#clojurechannel in our Discord server - here.
Clojure is designed to be hosted. This means that it runs on top of other languages. We'll learn about this property later in this course. For now, we just need to know that JVM and NodeJS are required to run Clojure.
Checking if JVM and Node are installed already#
Before getting started, we suggest that you check if your system has Node and Java installed already.
In a terminal, execute the command
If you get a version number like
javac 1.8.0_202, the JVM is installed and you can safely skip the JVM installation process.
Any Java version above 1.8 or higher is recommended (Java 1.8 is sometimes also referred to as Java 8. The next version is Java 11).
node -v will show the currently installed Node version. If it returns a number like
v12.16.1, you can skip the Node installation process.
The latest stable Node version is recommended. You can check the list of LTS Node versions on the Node Release Page.
Installing JVM/ JDK#
You can either work with Oracle's JDK, Adopt Open JDK or Open JDK. All three JDKs are identical in terms of development. The only difference is that Open JDK and Adopt have a more permissible license. Oracle JDK requires a license for commercial use.
If you do not have the JDK installed already, we suggest Adopt Open JDK. Detailed installation instructions can be found at the following URLs:
If you are on Windows or Mac, you can use the official installer. Just download the correct package based on your OS, and the graphical interface will guide you through it.
On Linux, Node is distributed for all major package managers (yum, apt etc) as
nodejs. You can find the install command depending on your distro here.
Clojure is available as a recipe on Homebrew.
brew tap clojure/tools
brew install clojure/tools/clojure
This recipe installs Clojure command line interface tools and can be used to run an interactive REPL.
Clojure on Windows require PowerShell 5. You can find detailed installation instructions here.
Clojure has an official bash script for handling installation on Linux machines. It expects that you already have
Java installed. You can run the script as follows:
curl -O https://download.clojure.org/install/linux-install-126.96.36.1997.sh
chmod +x linux-install-188.8.131.527.sh
If you'd like to change the default install location, refer to the docs.
Test Clojure installation#
If everything went fine, executing the command
clj in the terminal of your choice should start an interactive Clojure session:
Clojure might download some dependencies the first time you run this command.
This is a good time to run the customary Hello World! program.
user=> (println "Hello World!")
In this chapter, we installed Clojure and its required dependencies. In the next chapter we'll learn about LISP code and editor integration.