Installing Leiningen on Mac OS


I’ve been playing with Clojure for quite sometime now. It’s a functional language hosted on the JVM, with a growing community and a very rich ecosystem. You can find libraries for every major problem, but in case you cannot find, you can count on the interoperability with Java will bridge the gap.

Nowadays, every programming language and platform offer a development environment with a build tool as foundation. Take as example Maven, Gradle and Sbt. It isn’t different in the Clojure world. It uses Leiningen as a build and project management tool. So, I would like to share with you how I’ve managed to install and configure Leiningen on my Mac.

First, create the directory /Applications/clojure to store Clojure’s related tools:

$ sudo mkdir /Applications/clojure

Navigate to the new directory, download the Leiningen script and give to the downloaded file permission to execute:

$ cd /Applications/clojure
$ sudo curl -O
$ sudo chmod +x lein

Add the new directory to the $PATH to be able to execute it everywhere in your system. To do that, navigate to the directory /etc/paths.d and create a file named clojure.lein with the content /Applications/clojure:

$ cd /etc/paths.d/
$ sudo echo "/Applications/clojure" >> clojure.lein

If the output of the command above is “permission denied” then you don’t have enough privileges to add something to /etc/paths.d/. In this case, you can add lein exclusively to your user profile.

$ cd ~
$ echo “export PATH=$PATH:/Applications/clojure” >> .bash_profile

Close the current terminal and open a new one to activate the changes. Execute the following command to check whether the $PATH variable was correctly modified to include Leiningen’s path:

echo $PATH

You should be able to find the path /Applications/clojure concatenated within the value.

Finally, execute the command lein for the first time to install Leiningen:

$ lein

It will download the latest version of Leiningen and make you ready to program in Clojure. Start the Clojure REPL with the following command:

$ lein repl

Have fun with Clojure and Leiningen!

24 thoughts on “Installing Leiningen on Mac OS

  1. Hi there,
    thanks for the post.
    I’m having trouble with procedure. I follow everything and it seems to go well until i try

    echo $PATH

    I’m not getting “/Applications/clojure” anywhere on the line
    any idea where i may have gone wrong?
    OSX 10.7.5

    1. Did you close the current terminal window, explicitly closed the terminal app (cmd+q) and opened a new terminal window?

    2. Graeme after running this command: “sudo vi clojure.lein”

      You need to enter the text “/Applications/clojure:”

      so that you actually add the path to the file,

      then to save and exit you must type “Esc” then “:” then “x”

  2. Thanks for the post.
    I was struggling with installing leiningen on MacOS, installing from my user directory failed with weird errors but your recipe worked like a charm.

  3. Thanks for your wonderful guide. I was struggling with the vague instructions from, yours are 100 times clearer and better! I installed it without much problem , except the confusing $PATH step in clojure.lein, which should have meant (…to type in the content line “/Applications/clojure” in the file.) — sorry I am a bit lost in OSX environment. coming from Windows environment.

  4. Thanks for this guide. I hope that readers noticed the type and keyed chmod a+x?!

    Question – is it right that I cannot then use this Clojure folder to store my own projects? I tried and was denied but, my lappy allowed me to create a lein projects in …Public folder.

  5. Hey thanks for the great lein install tutorial, I got the real up and running in a few minutes. With the exception of a needing a quick refresher on Vi, everything was dead simple.

  6. …just a suggestion

    This was super helpful, but since I never use vi or vim adding “/Applications/clojure:” to the file clojure.lein was the painful part for me.

    I would post the steps I used to get it to work, but I do not remeber them exactly other than Google how to edit file using vim…

    I think it would be useful to expand on how actually edit the file step-by-step for others like me in the future.

    Of course this is nitpicking so let me say again that the instruction were super helpful.

    Thanks for posting this.

  7. Hi, This was going all right since I received a weird error when I execute lein :

    Warning: /Users/remiclaeys/.lein/self-installs/leiningen-2.7.0-standalone.jar.p
    Warning: ending: Not a directory
    curl: (23) Failed writing body (0 != 16384)
    Failed to download (exit code 23)
    It’s possible your HTTP client’s certificate store does not have the
    correct certificate authority needed. This is often caused by an
    out-of-date version of libssl. It’s also possible that you’re behind a
    firewall and haven’t set HTTP_PROXY and HTTPS_PROXY.

    I have no proxy right now or anything so I do not have an idea about what’s going on :/


    1. It might be just a temporary problem with the download server. I believe that if you try later it may work.

    1. I admit that the ‘path’ part is actually not that good. I will fix that by redefining the commands this way:

      $ cd /etc/paths.d/
      $ sudo echo "/Applications/clojure" >> clojure.lein

      Thanks four your feedback.

    1. It usually never happens because who starts programming in Clojure never leaves Clojure. But, just in case:

      1. Delete the directory /Applications/clojure
      2. Delete the file /etc/paths.d/clojure.lein

      You may need to use sudo to perform these operations.

      1. I did that but the problem is in Mac terminal, I keep getting a warning which says: ‘ .clojure.lein.swp: Permission denied ‘ How to resolve this issue!?

        1. me too, I’m getting an error when I type ‘sudo echo “/Applications/clojure” >> clojure.lein’

          error reads : “An error occurred while redirecting file ‘clojure.lein’
          open: Permission denied”

          can anyone help me?

          1. Apparently, your user doesn’t have sudo privileges, so you cannot perform administrative operations. As alternative, you can add the command to your user profile:

            $ cd ~
            $ echo “export PATH=$PATH:/Applications/clojure” >> .bash_profile
            $ source .bash_profile

            Then you can try to run lein:

            $ lein -v

            It may print something like Leiningen 2.6.1 on Java 1.8.0_111 OpenJDK 64-Bit Server VM. If it doesn’t, then close the terminal and open it again. If it still doesn’t work, then logout and login.

            Please, let me know if it works for you.

  8. Well, I sorted it by deleting another file called ‘.clojure.lein.swp’ from path.d folder.
    Thanks for your help though.

  9. Hi Mr. Mendonça, thank you so much for your reply! I just got around to seeing it. I actually did a factory reset on my Mac and was able to install Leiningen perfectly by following your steps.

  10. I’m a newbie and I’ll just write what I had trouble with.
    Editing the .bash_profile was really hard with Vi as I’ve never used it before. I didn’t expect the separate command mode.
    To add something in Vi, you have to enter the “insert mode” by pressing “i”. After you’ve modified your .bash_profile, you have to press esc to leave the insert mode, press “:” to enter commands and enter “x” to leave.
    Everythings fine now, except I couldn’t launch Lein from anywhere but the folder I installed it to. 😀

    If you have multiple paths in your .bash_profile, you have to add ~ in front of your address. Mine looks like this. The new addition is the last one.

    export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:~/Applications/clojure

    1. Hello, I’m not using Vi in the post anymore (I have removed it sometime ago). But you can actually use any text editor you like.

      I’m not quite sure you are using ~ properly. Maybe, that’s the reason why you can’t launch Lein anywhere but in the installation folder. The symbol ~ is a short reference to your home directory. When you write ~/Applications/clojure it means you are referencing the directory that is supposed to be at /Users/[username]/Applications/clojure, but /Applications is actually a root directory.

      So, your export PATH would be:

      export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/Applications/clojure

Leave a Reply

Your email address will not be published. Required fields are marked *