• Register
0 votes
133 views

Problem :

I am beginner to CentOS. I tried executing sudo ./startup.sh in my CentOS, But I am facing the below error:

"Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"

I have already defined them in my bashrc as shown below:

export JAVA_HOME=/home/mphil/New_learning/jdk1.8.0_212
export PATH=$JAVA_HOME/bin:$PATH

How to fix this error?

2.3k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I can say this is very basic mistake done by most of the beginners.

Please follow below approach to fix the error.

I can tell you one thing when you define them in your .bashrc file, it is really good and well defined for the your user.

But when you launch a command with the use of sudo, then it will run as the super-user/root, and NOT as the your user; so your current .bashrc file is 'useless' in this scenario.

In your case you must update the environment with your system file as shown below under the /etc/profile.d for example:

You need to write below commands very carefully

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/mphil/New_learning/jdk1.8.0_212
export PATH=$JAVA_HOME/bin:$PATH
EOF

Now you just need to restart your computer, and then your SYSTEM environment will know your $JAVA_HOME.

I hope it fixes your problem

5k points