简体   繁体   English

由于空间问题,WSL 无法找到文件或目录

[英]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.

相关问题 批处理文件查找目录中的文件 - Batch file to find files in a directory 在 WSL Ubuntu 20.04 上安装 npm 后,我收到消息“/usr/bin/env: 'bash\r': No such file or directory” - After installing npm on WSL Ubuntu 20.04 I get the message "/usr/bin/env: ‘bash\r’: No such file or directory" 无法将现有的 WSL1 发行版转换为 WSL2 - Not able to convert existing WSL1 distro to WSL2 错误:由于环境错误,无法安装软件包:[Errno 2] 没有这样的文件或目录: - ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 找到/ C“ A”将导致“查找:'A':无此类文件或目录” - find /C “A” results in “find: 'A': No such file or directory” 如果路径包含空格,则无法从VBScript启动bat文件 - Not able to launch bat file form VBScript if path contains a space 无法在pentaho数据集成中找到日志文件 - not able to find log file in pentaho data integration .bat文件-cd到名称中带有空格并且还使用变量的目录? - .bat file - cd to a directory with a space in its name and also using a variable? Perl File::Find Windows 反斜杠目录路径 - Perl File::Find Windows Backslashes Directory Path 在目录树中查找文件的最快方法是什么 - What is the fastest way to find a file in a directory tree
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM