Instructions on how to install the Clojure programming language on macOS.
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"
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 needs to be installed on your local computer. Instructions on how to install Java on macOS can be found here.
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"
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
Open a new terminal window and check if the Clojure programming language is installed:
clj -e nil
clj -e '(+ 1 1)'
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
After installing the Clojure programming language you can remove the downloaded package(s) using the following command:
rm -rf "${HOME}/.src"
The best description on this topic I've seen on the internet. Why would not use brew install clojure/tools/clojure so I don't have to mess with versions?