-1

On executing sudo ./startup.sh in CentOS, I am getting the following error:

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

But I have already defined it in bashrc in the following way:

export JAVA_HOME=/home/manish/New_learning/jdk1.8.0_212
export PATH=$JAVA_HOME/bin:$PATH
Eduardo Baitello
  • 10,469
  • 7
  • 46
  • 74
Manish
  • 11
  • 1
  • 1
  • 2
  • fyi, that leaves the issue of `JRE_HOME` not being defined. What happens when you type `sudo echo $JAVA_HOME && sudo ./startup.sh` instead ? Do you see a path being show for the java folder ? – Aserre Apr 25 '19 at 13:57
  • It does show path which I have added in bashrc file – Manish Apr 25 '19 at 16:10
  • 1
    I have tried without sudo but getting below error. ./startup.sh touch: cannot touch ‘/home/manish/New_learning/apache-tomcat-9.0.19-src/logs/catalina.out’: No such file or directory /home/manish/New_learning/apache-tomcat-9.0.19-src/bin/catalina.sh: line 464: /home/manish/New_learning/apache-tomcat-9.0.19-src/logs/catalina.out: No such file or directory – Manish Apr 25 '19 at 16:11

2 Answers2

0

When you define it in your .bashrc file, it will be OK and well defined for your user.

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.

You should update your environment with a system file like something under /etc/profile.d for instance:

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.

Bsquare ℬℬ
  • 4,423
  • 11
  • 24
  • 44
  • I have tried without sudo but getting below error. ./startup.sh touch: cannot touch ‘/home/manish/New_learning/apache-tomcat-9.0.19-src/logs/catalina.out’: No such file or directory /home/manish/New_learning/apache-tomcat-9.0.19-src/bin/catalina.sh: line 464: /home/manish/New_learning/apache-tomcat-9.0.19-src/logs/catalina.out: No such file or directory – Manish Apr 25 '19 at 15:49
  • Yes, because startup.sh script needs root privileges. So you must keep sudo BUT define your JRE/JDK variables somewhere else; I'm going to update my answer. – Bsquare ℬℬ Apr 26 '19 at 08:06
  • Is it OK for you? – Bsquare ℬℬ Apr 27 '19 at 13:36
0

Please Add in

../tomcat/bin/startup.sh

script with below java parameters syntax :

JAVA_HOME=/JDK/path/

PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

export PATH

export JAVA_HOME

Example

JAVA_HOME=/appl/prod/Protine/tomcat/jdk1.5.0_16/

PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

export PATH

export JAVA_HOME

It's working for me , hope it will work for you too.

Wajid Shaikh
  • 339
  • 3
  • 5