问题描述
我试图让WSL识别我的Windows安装的JAVA_HOME环境变量.我附上了bashrc中的内容以及Windows环境变量中的内容以及cmd和bash的输出.
I'm trying to get WSL to recognize my windows installed environmental variable of JAVA_HOME. I attached of what I have in my bashrc and what I have in my windows environmental variables along with outputs from cmd and bash.
bashrc的结尾是什么:
What's at the end of my bashrc:
export JAVA_HOME="/mnt/d/Program Files/Java/jdk-11.0.1"
export PATH="/mnt/d/Program Files/Java/jdk-11.0.1/bin:$PATH"
CMD输入/输出:
C:\Users\jaall>javac --version
javac 11.0.1
BASH输入/输出:
BASH INPUT/OUTPUT:
myubuntu_name@DESKTOP-LUK3BII:~$ javac --version
Command 'javac' not found, but can be installed with:
sudo apt install default-jdk
sudo apt install openjdk-11-jdk-headless
sudo apt install ecj
sudo apt install openjdk-8-jdk-headless
我已经坚持了一段时间,无法解决问题或无法在线找到可行的解决方案.谢谢!
I've been stuck on this for awhile and can't figure it out or find a working solution online. Thanks!
推荐答案
根据Biswapriyo的建议,您应该使用WSLENV.
As Biswapriyo suggested, you should use WSLENV.
-
打开PowerShell.然后将JAVA_HOME设置为您的Java安装路径.
Open PowerShell. Then set JAVA_HOME to the path to your java installation.
在您的情况下,运行setx JAVA_HOME "D:\Program Files\Java\jdk-11.0.1"
您应该看到一条消息,内容为:成功:指定的值已保存.
You should see a message that says "SUCCESS: Specified value was saved.
- 然后运行
setx WSLENV "JAVA_HOME/p"
您应该再次看到成功消息.
You should see the success message again.
- 在您的WSL bash提示符中键入"env".
此时您应该看到正确设置了JAVA_HOME.
You should see JAVA_HOME correctly set at this point.
注意:如果第2步不起作用,则可能要更改JAVA_HOME的路径以包含"\ bin"文件夹.
Note: If step 2 doesn't work, you might want to changing the path to JAVA_HOME to include the '\bin' folder.
这篇关于Linux的Windows子系统无法识别JAVA_HOME环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!