Browse Learn Clojure Foundations as a Java Developer

Fix Clojure Environment Variables

Fix Clojure setup problems caused by shell startup files, `PATH`, `JAVA_HOME`, editor-launched REPLs, proxy variables, and project commands running in different environments.

Environment variable bugs are process bugs. Your terminal, editor, REPL, Maven process, Gradle daemon, and CI job may not inherit the same environment. A Clojure command that works in one place and fails in another is often using a different PATH, JAVA_HOME, working directory, proxy setting, or classpath alias.

Do not start by editing every shell file. First capture the environment used by the failing process.

Variables That Matter

Variable What it controls
PATH Which java, clojure, clj, lein, mvn, and gradle executables are found first.
JAVA_HOME Which JDK Java-aware tools should use when they honor the variable.
HTTP_PROXY / HTTPS_PROXY Whether dependency downloads go through a corporate proxy.
NO_PROXY Hosts that should bypass the proxy.
MAVEN_OPTS / JAVA_TOOL_OPTIONS JVM options that can affect Clojure, Maven, Gradle, and tests.
CLJ_CONFIG Optional Clojure CLI config directory override; useful but dangerous if forgotten.

CLOJURE_HOME is usually not required for ordinary Clojure CLI use. If a guide tells you to set it, verify which tool actually reads it.

Capture the Failing Environment

From the failing terminal:

1pwd
2env | sort
3which java
4which clojure
5java -version
6clojure --version

From a Clojure process, print the values the JVM actually sees:

1(System/getProperty "java.version")
2(System/getProperty "java.home")
3(System/getenv "JAVA_HOME")
4(System/getenv "PATH")

If the terminal and editor disagree, the editor is probably launching the REPL from a different shell mode or with a custom command.

Shell Startup Files Can Mislead You

On Unix-like systems, login shells, interactive shells, and GUI-launched apps may read different startup files.

Shell context Common files involved
zsh login shell ~/.zprofile, then interactive config such as ~/.zshrc
zsh interactive terminal ~/.zshrc
bash login shell ~/.bash_profile, ~/.bash_login, or ~/.profile
bash interactive shell ~/.bashrc
GUI-launched editor Often does not inherit the same shell startup path as Terminal

Put durable setup in the file your actual workflow reads. If an editor starts the REPL directly, configure the editor command or environment explicitly instead of assuming it reads your terminal profile.

Fix PATH Without Guessing

Prefer putting the chosen JDK and tool locations before older installs.

1export JAVA_HOME=/path/to/jdk
2export PATH="$JAVA_HOME/bin:/opt/homebrew/bin:$PATH"

Then verify:

1which java
2which clojure
3java -version
4clojure --version

If which java still points somewhere unexpected, another shell file or version manager is modifying PATH later.

Dependency Downloads Need Network Variables Too

When dependency resolution fails only on a corporate network, inspect proxy and certificate assumptions before changing dependency coordinates.

Symptom Environment check
Maven Central or Clojars cannot be reached HTTP_PROXY, HTTPS_PROXY, NO_PROXY, Maven settings, and corporate TLS certificates.
Works in terminal but not editor Editor process does not inherit proxy variables.
Works locally but not CI CI job lacks proxy, credentials, or repository mirror configuration.
Works for Maven but not Clojure CLI Maven settings may have repository/proxy config that the Clojure CLI command path does not share.

Keep secret tokens and credentials out of shell config committed to Git. Use your team’s secret manager or CI secret mechanism.

Make the Fix Reproducible

After fixing the environment, document the command that should work:

1java -version
2clojure -Spath
3clojure -M:test

If the project uses Leiningen, Maven, or Gradle, document that command instead. The team needs one reliable path, not five local workarounds.

Knowledge Check

### Why can a Clojure command work in Terminal but fail from an editor? - [x] The editor may launch the REPL with a different environment, working directory, or command - [ ] Clojure cannot run inside editors - [ ] Environment variables only exist in Java code - [ ] Git ignores editor-launched processes > **Explanation:** GUI apps and editor integrations may not inherit the same shell startup files as your terminal. Check the process environment used by the failing REPL. ### Which variable controls which executable is found first? - [x] `PATH` - [ ] `CLASSPATH_ONLY` - [ ] `deps.edn` - [ ] `project.clj` > **Explanation:** `PATH` determines which command-line executable is found first when you run names such as `java`, `clojure`, or `lein`. ### Why is `CLOJURE_HOME` usually not the first variable to set? - [x] Ordinary Clojure CLI use normally relies on installed commands and `deps.edn`, not `CLOJURE_HOME` - [ ] It replaces `JAVA_HOME` - [ ] It is required by every JVM - [ ] It stores dependency versions > **Explanation:** Most modern Clojure setup issues are about `PATH`, `JAVA_HOME`, classpath construction, or network configuration, not `CLOJURE_HOME`.
Revised on Saturday, May 23, 2026