While Clojure enjoys excellent support from all popular text editors and IDEs this setup guide focuses on Atom Editor.
1) Installing Atom
Atom is a powerful yet lightweight text editor and development environment available for various operating systems like macOs, Windows and Linux.
Further reading & watching
2) Installing Atom Packages for Clojure
Next we will install a few packages that give Atom some Clojure super powers. Simply go to Atom > Preferences > + Install and search for the “lemmings” package (assembled by Martin Schurrer) which includes all the packages listed below.
A powerful Clojure REPL with auto-completion, docstrings and more
Enables proto-repl to draw graphs to help visualize data
Adds proto-repl support for the Clojure debugger Sayid
Used by Proto REPL to display the output of your REPL next to your code
Automatically balancing parentheses in your code based on indention
3) Installing VirtualBox
Since we’d like to have a consistent development experience across all platforms we will use a recent version of Ubuntu within a virtual machine.
VirtualBox is an open source tool for managing virtual machines.
4) Installing Vagrant
Next we’ll install Vagrant which is a very useful tool that can configure and automatically set up virtual machines for us.
Last but not least we will download a Vagrant configuration for our Clojure development environment on Ubuntu so we can get started.
Click on Clone or download.
Finale: Tying everything together
Next we can provision our development environment with vagrant up
If you do this for the first time this can take a while since Vagrant is downloading a recent version of Ubuntu and setting everything up for you. Perfect time to grab a cup of tea.
Once vagrant up is finished setting everything up there will be a running virtual machine waiting for you.
You can log into the virtual machine using vagrant ssh
Notice how the command line prompt changed its color to green. You are now within your Ubuntu virtual machine.
We can verify this by typing uname -a
Just for fun we can now start a Clojure REPL using lein repl
If you issue lein repl for the first time it can also take a little while.
Above we have evaluated (+ 1 2 3 4) to 10 in our Clojure REPL. Yay.
Once you’ve finished playing around with the Clojure REPL you can exit it using the keyboard combination CTRL+d
Now we are back at the command line prompt of our Ubuntu virtual machine. To log out of the virtual machine to get back to your host system
you can also use CTRL+d
We’re logged out now. Back in our host system.
We could log back in using vagrant ssh or shut down our virtual machine to free up resources for our host system using vagrant halt
If you type vagrant up you start our virtual machine again. This should now happen way faster compared to the first time since Vagrant doesn’t have to set up everything from scratch anymore.
Like a few minutes ago vagrant ssh gets you back into the virtual machine.
Now we will again start a Clojure REPL using lein but unlike last time we won’t work with the REPL within the terminal and instead start a headless REPL that we then can connect to from outside of the virtual machine.
lein repl :headless :host 0.0.0.0 :port 7888
Now we’ll connect Atom to our headless REPL within our virtual machine.
Open Atom and navigate to Packages > Command Palette > Toggle
Search for nrepl and select Proto Repl: Remote Nrepl Connection
Now you can enter localhost and 7888 to let Atom’s proto-repl package know where the Clojure REPL of your virtual machine is.
A proto-repl within Atom should appear. It is connected to your headless REPL of your Ubuntu virtual machine. Magic.
This means your Atom editor can now evaluate Clojure code even though Clojure is only available within your virtual machine. Pretty cool right? :)