In the previous article about Clojure we were learning what Clojure is and its basic operations. On this occasion we are going to show the Leiningen installation process, which can be considered the the easiest way to use Clojure as is mentioned on their official site. Alternative popular build toolchains are Boot and deps and clj. This time we will be showing the procedure for its installation on GNU/Linux and Windows systems. At the end of this post you will be able to install and use lein to interact with Clojure more comfortably.
What is Leiningen?
Leiningen is a build automation and dependency management tool for the simple configuration of software projects written in the Clojure programming language. It was created by Phil Hagelberg who started the project with the aim of simplifying the complexities of Apache Maven, while offering a way of describing the most common build requirements of Clojure projects in idiomatic Clojure. Leiningen’s motto is Automate Clojure projects without setting your hair on fire
Attention!!! Leiningen and Clojure require Java. OpenJDK version 8 is recommended at this time.
Access here for more information: https://www.java.com/
Install leiningen on Debian base systems
Installing leiningen package Debian and derivatives is simple:
sudo apt-get update sudo apt-get install leiningen
Install leiningen a script for GNU/Linux systems
- Download the lein script here
- Place it on your $PATH where your shell can find it (eg. ~/bin)
- Set it to be executable (chmod a+x ~/bin/lein)
- Run lein and it will download the self-install package
Install leiningen on Windows
- Download the lein.bat here and save it in C:\JavaLib\
- Open up File Explorer
- Right Click on This PC and select Properties
- On the left hand side of the new window select Advanced System Settings
- On the bottom of this screen select Environment Variables…
- Find the PATH variable
- Append ;C:\JavaLib; to the existing PATH variable
- Open up a command prompt and type in lein self-install. This will install lein.
3rd-party releases packages not supported by the Leiningen team
Also you can find some packages for others systems here
Let’s test the REPL
Now open your terminal or command prompt and type:
Later type this 3 inputs and check the result in each case:
- “hello world”
- (+ 2 3)
- (- 10 (* 10 9))
Check if you get the same results 😉
lein repl nREPL server started on port 46521 on host 127.0.0.1 - nrepl://127.0.0.1:46521 REPL-y 0.4.3, nREPL Clojure 1.10.0 OpenJDK 64-Bit Server VM 18.104.22.168+1-post-Debian-1deb10u2 Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) Javadoc: (javadoc java-object-or-class-here) Exit: Control+D or (exit) or (quit) Results: Stored in vars *1, *2, *3, an exception in *e user=> "hello world" "hello world" user=> (+ 2 3) 5 user=> (- 10 (* 10 9)) -80 user=> exit Bye for now!
Closing our interpreter
To close our REPL interpreter it will only be necessary to enter
It is also possible to exit with the key combination control + d.
I hope you found this first tutorial helpful. I plan to continue publishing tutorials about Clojure. If you have a question, recommendation or feedback please leave me a comment.