bash JAVA_HOME 和 JRE_HOME 环境变量均未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55849109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
提问by Manish
On executing sudo ./startup.sh
in CentOS, I am getting the following error:
sudo ./startup.sh
在 CentOS 中执行时,我收到以下错误:
"Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
“既没有定义 JAVA_HOME 也没有定义 JRE_HOME 环境变量”
But I have already defined it in bashrc in the following way:
但是我已经通过以下方式在 bashrc 中定义了它:
export JAVA_HOME=/home/manish/New_learning/jdk1.8.0_212
export PATH=$JAVA_HOME/bin:$PATH
回答by Bsquare ??
When you define it in your .bashrcfile, it will be OK and well defined for your user.
当你在你的.bashrc文件中定义它时,它会为你的用户定义好。
When you launch the command with sudo, it runs as super-user/root, and NOT as your user; so your .bashrc file is 'useless' in this case.
当您使用 sudo 启动命令时,它以超级用户/root 用户身份运行,而不是以您的用户身份运行;所以你的 .bashrc 文件在这种情况下是“无用的”。
You should update your environment with a system file like something under /etc/profile.dfor instance:
您应该使用系统文件更新您的环境,例如/etc/profile.d下的内容:
sudo touch /etc/profile.d/variousPath.sh
sudo chown bsquare /etc/profile.d/variousPath.sh
cat >> /etc/profile.d/variousPath.sh <<EOF
export JAVA_HOME=/home/manish/New_learning/jdk1.8.0_212
export PATH=$JAVA_HOME/bin:$PATH
EOF
Reboot your computer, and your SYSTEM environment will know $JAVA_HOME
.
重新启动您的计算机,您的 SYSTEM 环境就会知道$JAVA_HOME
。