Skip to content

Instantly share code, notes, and snippets.

@bhb
Last active September 15, 2022 00:50
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhb/b44235034b0cb62604a565165abec39f to your computer and use it in GitHub Desktop.
Save bhb/b44235034b0cb62604a565165abec39f to your computer and use it in GitHub Desktop.
How to set up Clojure on M1 using Homebrew: A thread

How to set up Clojure on M1 using Homebrew: A thread

I’m upgrading from a Mid 2014 MacBook Pro, so this isn’t a fair comparison to recent Intel machines, but if you’re like me and were waiting for a MacBook with a decent keyboard, you’ll see a big speed boost.

Non-scientific comparison - time to compile my ClojureScript project

  • Mid 2014 MacBook Pro - 14s
  • M1 Pro MacBook Pro (under Rosetta) - 17s
  • M1 Pro MacBook Pro (native) - 6s

Setting up Homebrew

First, make sure your architecture is reported correctly:

/usr/bin/uname -m should return arm64

If this doesn’t work, it’s because you’re running this command from a shell (or tmux) that is running under Rosetta. Change your shell for the following steps.

Install Homebrew as per the instructions here https://brew.sh . It's fine to install again even if you have Homebrew already.

It should ask to install in /opt/homebrew. If it doesn’t, see the previous step.

Going forward, you’ll be using /opt/homebrew/bin/brew to install M1 binaries, and /usr/local/bin/brew to uninstall the old Intel ones.

which brew should return /opt/homebrew/bin/brew .

Installing Clojure, Leiningen, and Java via Homebrew

Now you can install all your tools, including Zulu, which is a M1 native version of the JVM

arch -arm64 brew install zulu clojure/tools/clojure leiningen

Setting up jenv

Optional, but I find it handy to isntall jenv to manage JVM versions. If you skip this step, you’ll just need to set JAVA_HOME yourself

arch -arm64 brew install jenv
ls -al /Library/Java/JavaVirtualMachines/  # find the dir for zulu
jenv add /Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home
jenv versions # check that zulu is set up
jenv global zulu64-17.0.1

Confirming the installation

To confirm this all worked, run clojure or lein repl and check Activity Monitor. You should see a java process where the “Kind” is “Apple”, not “Intel”. Enjoy the performance boost!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment