使用 openSUSE,我下载了 jdk1.6.0_24 的 Oracle rpm 包,并希望将 java home 环境变量设置为 /usr/java/jdk1.6.0_24,但 /etc/alternatives 系统无法自动检测已安装的 JDK。update-alternatives 或其他方法都无法找到 jdk。
因此,我想在 BASH 脚本中手动检测 JAVA home。
如果我运行此命令:sudo find /usr -name 'jdk1.6*',我会得到以下结果:
如何将结果传输到环境变量中?我想要做这样的事情:
因此,我想在 BASH 脚本中手动检测 JAVA home。
如果我运行此命令:sudo find /usr -name 'jdk1.6*',我会得到以下结果:
/usr/java/jdk1.6.0_24
如何将结果传输到环境变量中?我想要做这样的事情:
#!/bin/bash
read in JAVA_HOME var from a file
if file doesnt exist
sudo find /usr -name 'jdk1.6*'
prompt user for which jdk is correct
set that choice to a variable
add the JDK to alternatives if it is missing
save variable to a file and dont prompt next time
set the alternatives java choice
fi
echo $JAVA_HOME