Skip to content

Instantly share code, notes, and snippets.

@fscm
Created April 21, 2020 14:38
Show Gist options
  • Save fscm/4e9b719c7556997d54068556a7101630 to your computer and use it in GitHub Desktop.
Save fscm/4e9b719c7556997d54068556a7101630 to your computer and use it in GitHub Desktop.
[macOS] Install Clojure programming language

[macOS] Install Clojure programming language

Instructions on how to install the Clojure programming language on macOS.

Uninstall

First step should be to unsinstall any previous Clojure installation. This step can be skipped if no Clojure programming language was previously installed.

This will completelly remove any Clojure programming language version previously installed. If you which to keep the libraries installed and your configurations you should skip the last command.

To uninstall any previous Clojure installations use the following commands:

sudo find "/usr/local/bin" -lname '*/Library/Frameworks/Clojure.framework/*' -delete
sudo rm -rf "/Library/Frameworks/Clojure.framework"
sudo rm -rf "${HOME}/.clojure" "${HOME}/.m2" "${HOME}/.lein"

Prerequisites

macOS Command Line Tools

macOS Command Line Tools needs to be installed on your local computer.

To install the Command Line Tools run the following command:

xcode-select --install

Java Development Kit

Java Development Kit needs to be installed on your local computer. Instructions on how to install Java on macOS can be found here.

Readline Wrapper

Readline Wrapper (rlwrap) needs to be installed on your local computer.

To install rlwrap run the following commands:

mkdir -p "${HOME}/.src/rlwrap/_build/readline"
curl --silent --location --retry 3 "https://ftp.gnu.org/gnu/readline/readline-8.0.tar.gz" | tar xz --no-same-owner --strip-components=1 -C "${HOME}/.src/rlwrap/_build/readline"
cd "${HOME}/.src/rlwrap/_build"
for i in 00{1..4}; do curl --silent --location --retry 3 "https://ftp.gnu.org/gnu/readline/readline-8.0-patches/readline80-${i}" | patch --silent --backup --strip=0 --directory='./readline/'; done
(cd ./readline/ && ./configure --quiet --prefix="${HOME}/.src/rlwrap/readline" SHLIB_LIBS='-lSystem -lncurses -lcc_dynamic' && make --silent && make --silent install)
curl --silent --location --retry 3 "https://github.com/hanslub42/rlwrap/releases/download/v0.43/rlwrap-0.43.tar.gz" | tar xz --no-same-owner --strip-components=1 -C "${HOME}/.src/rlwrap"
../configure CFLAGS="-I${HOME}/.src/rlwrap/readline/include" CPPFLAGS="-I${HOME}/.src/rlwrap/readline/include" LDFLAGS="-L${HOME}/.src/rlwrap/readline/lib" --quiet --prefix="/usr/local" --enable-silent-rules --disable-debug
make --silent
sudo make --silent install
rlwrap --version
cd -
rm -rf "${HOME}/.src/rlwrap"

Install

The Clojure Tools package, that will be used to install Closure, can be obtained from the download.clojure.org site.

To find the complete url get the relase version that you want to use from here and combine it with the link bellow.

https://download.clojure.org/install/clojure-tools-<VERSION>.tar.gz

Copy the link for the package version that you want to install into the next curl command.

Get the Clojure Tools package using the following commands:

mkdir -p "${HOME}/.src/clojure"
curl --silent --location --retry 3 "https://download.clojure.org/install/clojure-tools-1.10.1.536.tar.gz" | tar xz --no-same-owner --strip-components=1 -C "${HOME}/.src/clojure"
sed -i '.orig' -e '/^prefix=/a\'$'\n''mkdir -p "$prefix"' -e 's/${HOMEBREW_RUBY_PATH}/ruby/' "${HOME}/.src/clojure/install.sh"

Install Clojure using the following command:

_version_="$(sed -E -n -e 's/.*Version:[ ]+(.*)/\1/p' ~/.src/clojure/clojure)" \
  && (cd ~/.src/clojure && sudo ./install.sh "/Library/Frameworks/Clojure.framework/Versions/${_version_}") \
  && sudo ln -s "${_version_}" "/Library/Frameworks/Clojure.framework/Versions/Current" \
  && for p in "/Library/Frameworks/Clojure.framework/Versions/Current/bin/"*; do sudo ln -s -f -h "${p}" "/usr/local/bin/$(basename ${p})"; done

Verify

Open a new terminal window and check if the Clojure programming language is installed:

clj -e nil
clj -e '(+ 1 1)'

Leiningen

Leiningen is a tool to automate Clojure projects and can be obtained here. Copy the release version that you want to install and replace the value of the _version_ variable bellow.

Get and install the Leiningen tool using the following commands:

_version_="2.9.3" \
  && sudo curl --silent --location --retry 3 --output "/Library/Frameworks/Clojure.framework/Versions/Current/libexec/leiningen-${_version_}-standalone.jar" "https://github.com/technomancy/leiningen/releases/download/${_version_}/leiningen-${_version_}-standalone.zip" \
  && mkdir -p "${HOME}/.src/leiningen" \
  && curl --silent --location --retry 3 "https://github.com/technomancy/leiningen/archive/${_version_}.tar.gz" | tar xz --no-same-owner --strip-components=1 -C "${HOME}/.src/leiningen" \
  && sed -i '.orig' -e '/^LEIN_JAR=/ s,=.*,=/Library/Frameworks/Clojure.framework/Versions/Current/libexec/leiningen-$LEIN_VERSION-standalone.jar,' "${HOME}/.src/leiningen/bin/lein-pkg" \
  && sudo cp "${HOME}/.src/leiningen/bin/lein-pkg" "/Library/Frameworks/Clojure.framework/Versions/Current/bin/lein" \
  && sudo chmod 0755 "/Library/Frameworks/Clojure.framework/Versions/Current/bin/lein" \
  && sudo ln -s -f -h "/Library/Frameworks/Clojure.framework/Versions/Current/bin/lein" "/usr/local/bin/lein" \
  && rm -rf "${HOME}/.src/leiningen" \
  && lein help

Clean up

After installing the Clojure programming language you can remove the downloaded package(s) using the following command:

rm -rf "${HOME}/.src"
@fscm
Copy link
Author

fscm commented Jan 17, 2022

@wilsonmar There is nothing wrong in using brew. If you have brew installed then you should use it.
Not all people have brew installed and may not want to install it just to check/try a programming language (in this case).

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