As Biswapriyo suggested, you should use WSLENV.
-
Open PowerShell. Then set
JAVA_HOMEto the path to your java installation. -
In your case, run
setx JAVA_HOME "D:\Program Files\Java\jdk-11.0.1"
You should see a message that says “SUCCESS: Specified value was saved”.
- Then run
setx WSLENV "JAVA_HOME/p".
You should see the success message again.
- Type ‘env’ into your WSL bash prompt.
You should see JAVA_HOME correctly set at this point.
Note: If step 2 doesn’t work, you might want to changing the path to JAVA_HOME to include the \bin folder.