[英]WSL Not able to find file or directory due to space
The error I was originally getting was that wsl was not able to find JAVA_HOME.我最初得到的错误是wsl找不到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!任何帮助,将不胜感激!
It looks like you are trying to use the Windows version of Java from within WSL.看起来您正在尝试从 WSL 中使用 Java 的 Windows 版本。 That should be possible, but you are currently exporting a Linux-style path, which the Windows version won't handle (as you can see).
这应该是可能的,但是您当前正在导出 Linux 样式的路径,Windows 版本无法处理(如您所见)。
If you have both the Windows and Linux version of Java installed, then see this answer for some related information.如果您同时安装了 Windows 和 Linux 版本的 Java,请参阅此答案以获取一些相关信息。 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.
有关于 npm 的问题,但核心问题是相同的——Windows 版本在 Linux 版本之前的路径中被选中。
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).如果您只有 Windows 版本,那么至少将
JAVA_HOME
修改为 'C:\Program Files\JAVA\jdk-15.0.2'(不过,请注意 Linux-shell 字符串中反斜杠的潜在引用问题)。 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.我不确定这是否能解决您的所有问题——我从未尝试过自己通过 WSL 运行 Windows Java 版本。 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 .执行
${JAVA_HOME}
时的第二个错误是意料之中的,因为您正尝试将此目录(带有空格)作为命令执行。 The shell is interpreting the portion before the space as a command, and the portion after the space as the argument. shell 将空格之前的部分解释为命令,将空格之后的部分解释为参数。 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
.如果您将其设置为没有空格的目录,则在尝试执行它时仍然会收到错误消息(就像您现在一样),只是它会类似于
bash: /mnt/c: Is a directory
.
If you just want to check it, use echo ${JAVA_HOME}
.如果您只想检查它,请使用
echo ${JAVA_HOME}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.