0

The error I was originally getting was that wsl was not able to find JAVA_HOME. After I ran the command

export JAVA_HOME="/mnt/c/Program Files/JAVA/jdk-15.0.2"

And now the error it gives me is:

ERROR: JAVA_HOME is set to an invalid directory: /mnt/c/Program Files/Java/jdk-15.0.2

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

When I run

${JAVA_HOME}

to check the variable I get the response

bash: /mnt/c/Program: No such file or directory

Which I believe is due to the space in the file name. Online it said that the space shouldn't be an issue as it is enclosed in quotes so I don't know what to do here.

Any help would be appreciated!

Alfred T
  • 73
  • 1
  • 1
  • 5
  • Use `echo $JAVA_HOME` to see your variable. As you said, the spacing issue doesn't seem to be a problem for Java because it's in quotes. I suggest going to the directory in question, doing `pwd` to get the path, copy that and paste into JAVA_HOME and try again. – wxz Mar 08 '21 at 21:23
  • 1
    Also, since this is WSL, I notice that you're trying to use the Windows version of Java (given it's stored in the Windows c/Program Files/ ) from inside linux. Another thing to try is using the linux java that you can install with apt instead of the windows version. – wxz Mar 08 '21 at 21:42

1 Answers1

1

It looks like you are trying to use the Windows version of Java from within WSL. That should be possible, but you are currently exporting a Linux-style path, which the Windows version won't handle (as you can see).

If you have both the Windows and Linux version of Java installed, then see this answer for some related information. The question there is about npm, but the core issue is the same -- The Windows version is getting picked up in the path before the Linux version.

If you just have the Windows version, then at least modify the JAVA_HOME to be 'C:\Program Files\JAVA\jdk-15.0.2' (watch out for potential quoting issues with backslashes in the Linux-shell string, though). I'm not sure that's going to take care of all of your issues -- I've never tried running the Windows Java version through WSL myself. But it's at least the first step you're going to need to take to get past the current error.

The second error when you just execute ${JAVA_HOME} is to be expected, as you are trying to execute this directory (with a space) as a command. The shell is interpreting the portion before the space as a command, and the portion after the space as the argument. If you were to set it to a directory without a space, you'd still get an error message when trying to execute it (as you are now), just that it would be something like bash: /mnt/c: Is a directory.

If you just want to check it, use echo ${JAVA_HOME}.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
  • I've tried changing my JAVA_HOME to that windows path you suggested but it still says its an invalid directory. I also tried installing java via sudo for the Linux version and that doesn't seem to change anything either – Alfred T Mar 08 '21 at 23:55
  • I don't have an instance set up this at the moment with Java, so I can't provide detailed directions. I'll try to clone an instance later today to test for myself. In the meantime, after installing it into Linux, what does `which java` give you? – NotTheDr01ds Mar 09 '21 at 20:23
  • `which java` gives me /usr/bin/java. Setting my JAVA_HOME to that doesn't work either :( – Alfred T Mar 09 '21 at 21:46