Tomcat does not recognize JAVA_HOME The 2019 Stack Overflow Developer Survey Results Are InWhy ~/.bash_profile is not getting sourced when opening a terminal?Environment variable is set but not accessible on serverPATH is not getting exported by default in Ubuntu 12.04Some error messages displayed when I start terminal (both as root and as normal user)How to Verify JAVA_HOME pathPath given in Environment variable shows empty after rebootHow to set JAVA_HOME for all users for “elasticsearch” program?Why I can't use the CATALINA_HOME environment variable?Tomcat 7 as a service under systemctl in 18.04 -configuration?[SOLVED]How to set up JAVA_HOME when connect through ssh and using Bourne compatible Shell?

What is the most effective way of iterating a std::vector and why?

If a Druid sees an animal’s corpse, can they Wild Shape into that animal?

What did it mean to "align" a radio?

When should I buy a clipper card after flying to OAK?

For what reasons would an animal species NOT cross a *horizontal* land bridge?

What does ひと匙 mean in this manga and has it been used colloquially?

Deal with toxic manager when you can't quit

Is a "Democratic" Oligarchy-Style System Possible?

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

Looking for Correct Greek Translation for Heraclitus

Why didn't the Event Horizon Telescope team mention Sagittarius A*?

Why did Acorn's A3000 have red function keys?

Time travel alters history but people keep saying nothing's changed

What is the motivation for a law requiring 2 parties to consent for recording a conversation

Why can Shazam fly?

What is the accessibility of a package's `Private` context variables?

Is an up-to-date browser secure on an out-of-date OS?

How come people say “Would of”?

Why isn't airport relocation done gradually?

Delete all lines which don't have n characters before delimiter

Distributing a matrix

slides for 30min~1hr skype tenure track application interview

Why hard-Brexiteers don't insist on a hard border to prevent illegal immigration after Brexit?

What do the Banks children have against barley water?



Tomcat does not recognize JAVA_HOME



The 2019 Stack Overflow Developer Survey Results Are InWhy ~/.bash_profile is not getting sourced when opening a terminal?Environment variable is set but not accessible on serverPATH is not getting exported by default in Ubuntu 12.04Some error messages displayed when I start terminal (both as root and as normal user)How to Verify JAVA_HOME pathPath given in Environment variable shows empty after rebootHow to set JAVA_HOME for all users for “elasticsearch” program?Why I can't use the CATALINA_HOME environment variable?Tomcat 7 as a service under systemctl in 18.04 -configuration?[SOLVED]How to set up JAVA_HOME when connect through ssh and using Bourne compatible Shell?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








14















I've installed Ubuntu 14.04 Server, extracted JDK1.8u5 and Tomcat7, and added the following to .profile (I also tried adding it to .bashrc with similar [non-] results):



export JAVA_HOME=/opt/java/jdk1.8.0_05
export PATH=$PATH:$JAVA_HOME/bin


when I run echo $JAVA_HOME I get the expected result of /opt/java/jdk1.8.0_05. I can also run java -version and get the correct response from Java. so far so good.



so now I try to startup Tomcat (tried also catalina.sh), and I get the following:



user@ubuntu:~$ sudo /opt/tomcat7/apache-tomcat-7.0.53/bin/startup.sh
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program


but... I just tried echo $JAVA_HOME and it worked?










share|improve this question






























    14















    I've installed Ubuntu 14.04 Server, extracted JDK1.8u5 and Tomcat7, and added the following to .profile (I also tried adding it to .bashrc with similar [non-] results):



    export JAVA_HOME=/opt/java/jdk1.8.0_05
    export PATH=$PATH:$JAVA_HOME/bin


    when I run echo $JAVA_HOME I get the expected result of /opt/java/jdk1.8.0_05. I can also run java -version and get the correct response from Java. so far so good.



    so now I try to startup Tomcat (tried also catalina.sh), and I get the following:



    user@ubuntu:~$ sudo /opt/tomcat7/apache-tomcat-7.0.53/bin/startup.sh
    Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
    At least one of these environment variable is needed to run this program


    but... I just tried echo $JAVA_HOME and it worked?










    share|improve this question


























      14












      14








      14


      6






      I've installed Ubuntu 14.04 Server, extracted JDK1.8u5 and Tomcat7, and added the following to .profile (I also tried adding it to .bashrc with similar [non-] results):



      export JAVA_HOME=/opt/java/jdk1.8.0_05
      export PATH=$PATH:$JAVA_HOME/bin


      when I run echo $JAVA_HOME I get the expected result of /opt/java/jdk1.8.0_05. I can also run java -version and get the correct response from Java. so far so good.



      so now I try to startup Tomcat (tried also catalina.sh), and I get the following:



      user@ubuntu:~$ sudo /opt/tomcat7/apache-tomcat-7.0.53/bin/startup.sh
      Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
      At least one of these environment variable is needed to run this program


      but... I just tried echo $JAVA_HOME and it worked?










      share|improve this question
















      I've installed Ubuntu 14.04 Server, extracted JDK1.8u5 and Tomcat7, and added the following to .profile (I also tried adding it to .bashrc with similar [non-] results):



      export JAVA_HOME=/opt/java/jdk1.8.0_05
      export PATH=$PATH:$JAVA_HOME/bin


      when I run echo $JAVA_HOME I get the expected result of /opt/java/jdk1.8.0_05. I can also run java -version and get the correct response from Java. so far so good.



      so now I try to startup Tomcat (tried also catalina.sh), and I get the following:



      user@ubuntu:~$ sudo /opt/tomcat7/apache-tomcat-7.0.53/bin/startup.sh
      Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
      At least one of these environment variable is needed to run this program


      but... I just tried echo $JAVA_HOME and it worked?







      bash java environment-variables tomcat






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 18 '14 at 22:52









      Braiam

      52.6k20138223




      52.6k20138223










      asked May 18 '14 at 17:45









      isapirisapir

      183129




      183129




















          4 Answers
          4






          active

          oldest

          votes


















          18














          There is a help text in catalina.sh. I will quote it here:



          # Do not set the variables in this script. Instead put them into a script
          # setenv.sh in CATALINA_BASE/bin to keep your customizations separate.

          #
          # JAVA_HOME Must point at your Java Development Kit installation.
          # Required to run the with the "debug" argument.

          # Ensure that any user defined CLASSPATH variables are not used on startup,
          # but allow them to be specified in setenv.sh, in rare case when it is needed.
          CLASSPATH=

          if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
          . "$CATALINA_BASE/bin/setenv.sh"
          elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
          . "$CATALINA_HOME/bin/setenv.sh"
          fi


          When you starting tomcat using catalina.sh, it searching for file setenv.sh and sourcing it. It is searching in CATALINA_HOME or CATALINA_BASE.



          So the better way to set JAVA_HOME for the tomcat is:



          1. Create a script named setenv.sh in the folder CATALINA_BASE/bin, if it does not exist already.


          2. Add this line to setenv.sh



            export JAVA_HOME=/opt/java/jdk1.8.0_05


          3. Make it executable.



          Why you should use this solution:



          Setting environment variable in script is safer. Always try to set variables as locally as possible. Try do not use /etc/environment, /etc/profile and others if you really do not need Global Environment Variable. Setting JAVA_HOME in setenv.sh gives you ability to use different tomcats with different applications that need different version of java, but running by one user. Other user environment would not be affected by you.






          share|improve this answer
































            4














            Since you have set the environment variable for your own user and not for the superuser, you have two options:




            1. You will have to export the variable using -E option as follows:



              sudo -E /opt/tomcat7/apache-tomcat-7.0.53/bin/startup.sh


              Note that this will export all environment variables while running the command. This is not preferred since the normal users environment is spilled out when you run the command as root. This is not desirable.




            2. Export the variable in root's .bashrc /etc/enviroment file. Open a terminal and type:



              sudo nano /etc/environment


              and enter your administrative password, and add the following lines to the end of the file:



              JAVA_HOME=/opt/java/jdk1.8.0_05
              PATH=$PATH:$JAVA_HOME/bin


              and then



              source /etc/environment


              or restart your machine and then retry the command you were using.




            Update:



            This answer provided hints as two why step 2 wouldn't work, sudo would reset the environment and provide a secure path, so all global variables are reset. A workaround would be to use



            sudo su


            and then execute command which uses the set environment variables.






            share|improve this answer




















            • 1





              Thanks @Jobin -- option 1 works so I upvoted your answer. I will now check option 2, which is my preferred solution, and if it works I will accept your answer.

              – isapir
              May 18 '14 at 17:57











            • I added the commands to /root/.bashrc with nano, as you suggested, but calling user@ubuntu:~$ source /root/.bashrc results in -bash: /root/.bashrc: Permission denied and trying it with sudo yields sudo: source: command not found. retrying the original command at this point brings me back to point 0.

              – isapir
              May 18 '14 at 18:05











            • @Igal: Edited my answer to solve that issue, you should first use sudo -i before you source. Thanks for pointing that out.

              – jobin
              May 18 '14 at 18:06











            • ok, pardon the newbie questions, but how do I exit the sudo -i once I'vet called source? without exiting I am getting the original error message...

              – isapir
              May 18 '14 at 18:08











            • @Igal: Just press Ctrl + d or type exit.

              – jobin
              May 18 '14 at 18:09



















            0














            The solution I was looking for is in /etc/environment which, as specified at EnvironmentVariables, does not process scripts and does not expand variables, so adding the following (without export) did the trick:



            JAVA_HOME=/opt/java/jdk1.8.0_05


            Then I rebooted the system for the changes to take affect.






            share|improve this answer






























              0














              I added JAVA_HOME in tomcat7.service script as setenv.sh was not get sourced by catalina.sh



              Steps:



              1.Open tomcat7 service script file



              sudo gedit /etc/init.d/tomcat7



              2.Set JAVA_HOME



              .
              .
              .
              JAVA_HOME=/usr/lib/jvm/java-8-oracle

              # Directory where the Tomcat 6 binary distribution resides
              CATALINA_HOME=/usr/share/$NAME

              # Directory for per-instance configuration files and webapps
              CATALINA_BASE=/var/lib/$NAME

              # Use the Java security manager? (yes/no)
              TOMCAT7_SECURITY=no


              3.Start tomcat7 service



              sudo service tomcat7 status






              share|improve this answer








              New contributor




              CᴴᴀZ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















                Your Answer








                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "89"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f468772%2ftomcat-does-not-recognize-java-home%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                18














                There is a help text in catalina.sh. I will quote it here:



                # Do not set the variables in this script. Instead put them into a script
                # setenv.sh in CATALINA_BASE/bin to keep your customizations separate.

                #
                # JAVA_HOME Must point at your Java Development Kit installation.
                # Required to run the with the "debug" argument.

                # Ensure that any user defined CLASSPATH variables are not used on startup,
                # but allow them to be specified in setenv.sh, in rare case when it is needed.
                CLASSPATH=

                if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
                . "$CATALINA_BASE/bin/setenv.sh"
                elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
                . "$CATALINA_HOME/bin/setenv.sh"
                fi


                When you starting tomcat using catalina.sh, it searching for file setenv.sh and sourcing it. It is searching in CATALINA_HOME or CATALINA_BASE.



                So the better way to set JAVA_HOME for the tomcat is:



                1. Create a script named setenv.sh in the folder CATALINA_BASE/bin, if it does not exist already.


                2. Add this line to setenv.sh



                  export JAVA_HOME=/opt/java/jdk1.8.0_05


                3. Make it executable.



                Why you should use this solution:



                Setting environment variable in script is safer. Always try to set variables as locally as possible. Try do not use /etc/environment, /etc/profile and others if you really do not need Global Environment Variable. Setting JAVA_HOME in setenv.sh gives you ability to use different tomcats with different applications that need different version of java, but running by one user. Other user environment would not be affected by you.






                share|improve this answer





























                  18














                  There is a help text in catalina.sh. I will quote it here:



                  # Do not set the variables in this script. Instead put them into a script
                  # setenv.sh in CATALINA_BASE/bin to keep your customizations separate.

                  #
                  # JAVA_HOME Must point at your Java Development Kit installation.
                  # Required to run the with the "debug" argument.

                  # Ensure that any user defined CLASSPATH variables are not used on startup,
                  # but allow them to be specified in setenv.sh, in rare case when it is needed.
                  CLASSPATH=

                  if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
                  . "$CATALINA_BASE/bin/setenv.sh"
                  elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
                  . "$CATALINA_HOME/bin/setenv.sh"
                  fi


                  When you starting tomcat using catalina.sh, it searching for file setenv.sh and sourcing it. It is searching in CATALINA_HOME or CATALINA_BASE.



                  So the better way to set JAVA_HOME for the tomcat is:



                  1. Create a script named setenv.sh in the folder CATALINA_BASE/bin, if it does not exist already.


                  2. Add this line to setenv.sh



                    export JAVA_HOME=/opt/java/jdk1.8.0_05


                  3. Make it executable.



                  Why you should use this solution:



                  Setting environment variable in script is safer. Always try to set variables as locally as possible. Try do not use /etc/environment, /etc/profile and others if you really do not need Global Environment Variable. Setting JAVA_HOME in setenv.sh gives you ability to use different tomcats with different applications that need different version of java, but running by one user. Other user environment would not be affected by you.






                  share|improve this answer



























                    18












                    18








                    18







                    There is a help text in catalina.sh. I will quote it here:



                    # Do not set the variables in this script. Instead put them into a script
                    # setenv.sh in CATALINA_BASE/bin to keep your customizations separate.

                    #
                    # JAVA_HOME Must point at your Java Development Kit installation.
                    # Required to run the with the "debug" argument.

                    # Ensure that any user defined CLASSPATH variables are not used on startup,
                    # but allow them to be specified in setenv.sh, in rare case when it is needed.
                    CLASSPATH=

                    if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
                    . "$CATALINA_BASE/bin/setenv.sh"
                    elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
                    . "$CATALINA_HOME/bin/setenv.sh"
                    fi


                    When you starting tomcat using catalina.sh, it searching for file setenv.sh and sourcing it. It is searching in CATALINA_HOME or CATALINA_BASE.



                    So the better way to set JAVA_HOME for the tomcat is:



                    1. Create a script named setenv.sh in the folder CATALINA_BASE/bin, if it does not exist already.


                    2. Add this line to setenv.sh



                      export JAVA_HOME=/opt/java/jdk1.8.0_05


                    3. Make it executable.



                    Why you should use this solution:



                    Setting environment variable in script is safer. Always try to set variables as locally as possible. Try do not use /etc/environment, /etc/profile and others if you really do not need Global Environment Variable. Setting JAVA_HOME in setenv.sh gives you ability to use different tomcats with different applications that need different version of java, but running by one user. Other user environment would not be affected by you.






                    share|improve this answer















                    There is a help text in catalina.sh. I will quote it here:



                    # Do not set the variables in this script. Instead put them into a script
                    # setenv.sh in CATALINA_BASE/bin to keep your customizations separate.

                    #
                    # JAVA_HOME Must point at your Java Development Kit installation.
                    # Required to run the with the "debug" argument.

                    # Ensure that any user defined CLASSPATH variables are not used on startup,
                    # but allow them to be specified in setenv.sh, in rare case when it is needed.
                    CLASSPATH=

                    if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
                    . "$CATALINA_BASE/bin/setenv.sh"
                    elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
                    . "$CATALINA_HOME/bin/setenv.sh"
                    fi


                    When you starting tomcat using catalina.sh, it searching for file setenv.sh and sourcing it. It is searching in CATALINA_HOME or CATALINA_BASE.



                    So the better way to set JAVA_HOME for the tomcat is:



                    1. Create a script named setenv.sh in the folder CATALINA_BASE/bin, if it does not exist already.


                    2. Add this line to setenv.sh



                      export JAVA_HOME=/opt/java/jdk1.8.0_05


                    3. Make it executable.



                    Why you should use this solution:



                    Setting environment variable in script is safer. Always try to set variables as locally as possible. Try do not use /etc/environment, /etc/profile and others if you really do not need Global Environment Variable. Setting JAVA_HOME in setenv.sh gives you ability to use different tomcats with different applications that need different version of java, but running by one user. Other user environment would not be affected by you.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 5 '16 at 8:44









                    muru

                    1




                    1










                    answered May 18 '14 at 18:41









                    c0rpc0rp

                    7,03612657




                    7,03612657























                        4














                        Since you have set the environment variable for your own user and not for the superuser, you have two options:




                        1. You will have to export the variable using -E option as follows:



                          sudo -E /opt/tomcat7/apache-tomcat-7.0.53/bin/startup.sh


                          Note that this will export all environment variables while running the command. This is not preferred since the normal users environment is spilled out when you run the command as root. This is not desirable.




                        2. Export the variable in root's .bashrc /etc/enviroment file. Open a terminal and type:



                          sudo nano /etc/environment


                          and enter your administrative password, and add the following lines to the end of the file:



                          JAVA_HOME=/opt/java/jdk1.8.0_05
                          PATH=$PATH:$JAVA_HOME/bin


                          and then



                          source /etc/environment


                          or restart your machine and then retry the command you were using.




                        Update:



                        This answer provided hints as two why step 2 wouldn't work, sudo would reset the environment and provide a secure path, so all global variables are reset. A workaround would be to use



                        sudo su


                        and then execute command which uses the set environment variables.






                        share|improve this answer




















                        • 1





                          Thanks @Jobin -- option 1 works so I upvoted your answer. I will now check option 2, which is my preferred solution, and if it works I will accept your answer.

                          – isapir
                          May 18 '14 at 17:57











                        • I added the commands to /root/.bashrc with nano, as you suggested, but calling user@ubuntu:~$ source /root/.bashrc results in -bash: /root/.bashrc: Permission denied and trying it with sudo yields sudo: source: command not found. retrying the original command at this point brings me back to point 0.

                          – isapir
                          May 18 '14 at 18:05











                        • @Igal: Edited my answer to solve that issue, you should first use sudo -i before you source. Thanks for pointing that out.

                          – jobin
                          May 18 '14 at 18:06











                        • ok, pardon the newbie questions, but how do I exit the sudo -i once I'vet called source? without exiting I am getting the original error message...

                          – isapir
                          May 18 '14 at 18:08











                        • @Igal: Just press Ctrl + d or type exit.

                          – jobin
                          May 18 '14 at 18:09
















                        4














                        Since you have set the environment variable for your own user and not for the superuser, you have two options:




                        1. You will have to export the variable using -E option as follows:



                          sudo -E /opt/tomcat7/apache-tomcat-7.0.53/bin/startup.sh


                          Note that this will export all environment variables while running the command. This is not preferred since the normal users environment is spilled out when you run the command as root. This is not desirable.




                        2. Export the variable in root's .bashrc /etc/enviroment file. Open a terminal and type:



                          sudo nano /etc/environment


                          and enter your administrative password, and add the following lines to the end of the file:



                          JAVA_HOME=/opt/java/jdk1.8.0_05
                          PATH=$PATH:$JAVA_HOME/bin


                          and then



                          source /etc/environment


                          or restart your machine and then retry the command you were using.




                        Update:



                        This answer provided hints as two why step 2 wouldn't work, sudo would reset the environment and provide a secure path, so all global variables are reset. A workaround would be to use



                        sudo su


                        and then execute command which uses the set environment variables.






                        share|improve this answer




















                        • 1





                          Thanks @Jobin -- option 1 works so I upvoted your answer. I will now check option 2, which is my preferred solution, and if it works I will accept your answer.

                          – isapir
                          May 18 '14 at 17:57











                        • I added the commands to /root/.bashrc with nano, as you suggested, but calling user@ubuntu:~$ source /root/.bashrc results in -bash: /root/.bashrc: Permission denied and trying it with sudo yields sudo: source: command not found. retrying the original command at this point brings me back to point 0.

                          – isapir
                          May 18 '14 at 18:05











                        • @Igal: Edited my answer to solve that issue, you should first use sudo -i before you source. Thanks for pointing that out.

                          – jobin
                          May 18 '14 at 18:06











                        • ok, pardon the newbie questions, but how do I exit the sudo -i once I'vet called source? without exiting I am getting the original error message...

                          – isapir
                          May 18 '14 at 18:08











                        • @Igal: Just press Ctrl + d or type exit.

                          – jobin
                          May 18 '14 at 18:09














                        4












                        4








                        4







                        Since you have set the environment variable for your own user and not for the superuser, you have two options:




                        1. You will have to export the variable using -E option as follows:



                          sudo -E /opt/tomcat7/apache-tomcat-7.0.53/bin/startup.sh


                          Note that this will export all environment variables while running the command. This is not preferred since the normal users environment is spilled out when you run the command as root. This is not desirable.




                        2. Export the variable in root's .bashrc /etc/enviroment file. Open a terminal and type:



                          sudo nano /etc/environment


                          and enter your administrative password, and add the following lines to the end of the file:



                          JAVA_HOME=/opt/java/jdk1.8.0_05
                          PATH=$PATH:$JAVA_HOME/bin


                          and then



                          source /etc/environment


                          or restart your machine and then retry the command you were using.




                        Update:



                        This answer provided hints as two why step 2 wouldn't work, sudo would reset the environment and provide a secure path, so all global variables are reset. A workaround would be to use



                        sudo su


                        and then execute command which uses the set environment variables.






                        share|improve this answer















                        Since you have set the environment variable for your own user and not for the superuser, you have two options:




                        1. You will have to export the variable using -E option as follows:



                          sudo -E /opt/tomcat7/apache-tomcat-7.0.53/bin/startup.sh


                          Note that this will export all environment variables while running the command. This is not preferred since the normal users environment is spilled out when you run the command as root. This is not desirable.




                        2. Export the variable in root's .bashrc /etc/enviroment file. Open a terminal and type:



                          sudo nano /etc/environment


                          and enter your administrative password, and add the following lines to the end of the file:



                          JAVA_HOME=/opt/java/jdk1.8.0_05
                          PATH=$PATH:$JAVA_HOME/bin


                          and then



                          source /etc/environment


                          or restart your machine and then retry the command you were using.




                        Update:



                        This answer provided hints as two why step 2 wouldn't work, sudo would reset the environment and provide a secure path, so all global variables are reset. A workaround would be to use



                        sudo su


                        and then execute command which uses the set environment variables.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited May 19 '14 at 7:22

























                        answered May 18 '14 at 17:53









                        jobinjobin

                        19.7k1279109




                        19.7k1279109







                        • 1





                          Thanks @Jobin -- option 1 works so I upvoted your answer. I will now check option 2, which is my preferred solution, and if it works I will accept your answer.

                          – isapir
                          May 18 '14 at 17:57











                        • I added the commands to /root/.bashrc with nano, as you suggested, but calling user@ubuntu:~$ source /root/.bashrc results in -bash: /root/.bashrc: Permission denied and trying it with sudo yields sudo: source: command not found. retrying the original command at this point brings me back to point 0.

                          – isapir
                          May 18 '14 at 18:05











                        • @Igal: Edited my answer to solve that issue, you should first use sudo -i before you source. Thanks for pointing that out.

                          – jobin
                          May 18 '14 at 18:06











                        • ok, pardon the newbie questions, but how do I exit the sudo -i once I'vet called source? without exiting I am getting the original error message...

                          – isapir
                          May 18 '14 at 18:08











                        • @Igal: Just press Ctrl + d or type exit.

                          – jobin
                          May 18 '14 at 18:09













                        • 1





                          Thanks @Jobin -- option 1 works so I upvoted your answer. I will now check option 2, which is my preferred solution, and if it works I will accept your answer.

                          – isapir
                          May 18 '14 at 17:57











                        • I added the commands to /root/.bashrc with nano, as you suggested, but calling user@ubuntu:~$ source /root/.bashrc results in -bash: /root/.bashrc: Permission denied and trying it with sudo yields sudo: source: command not found. retrying the original command at this point brings me back to point 0.

                          – isapir
                          May 18 '14 at 18:05











                        • @Igal: Edited my answer to solve that issue, you should first use sudo -i before you source. Thanks for pointing that out.

                          – jobin
                          May 18 '14 at 18:06











                        • ok, pardon the newbie questions, but how do I exit the sudo -i once I'vet called source? without exiting I am getting the original error message...

                          – isapir
                          May 18 '14 at 18:08











                        • @Igal: Just press Ctrl + d or type exit.

                          – jobin
                          May 18 '14 at 18:09








                        1




                        1





                        Thanks @Jobin -- option 1 works so I upvoted your answer. I will now check option 2, which is my preferred solution, and if it works I will accept your answer.

                        – isapir
                        May 18 '14 at 17:57





                        Thanks @Jobin -- option 1 works so I upvoted your answer. I will now check option 2, which is my preferred solution, and if it works I will accept your answer.

                        – isapir
                        May 18 '14 at 17:57













                        I added the commands to /root/.bashrc with nano, as you suggested, but calling user@ubuntu:~$ source /root/.bashrc results in -bash: /root/.bashrc: Permission denied and trying it with sudo yields sudo: source: command not found. retrying the original command at this point brings me back to point 0.

                        – isapir
                        May 18 '14 at 18:05





                        I added the commands to /root/.bashrc with nano, as you suggested, but calling user@ubuntu:~$ source /root/.bashrc results in -bash: /root/.bashrc: Permission denied and trying it with sudo yields sudo: source: command not found. retrying the original command at this point brings me back to point 0.

                        – isapir
                        May 18 '14 at 18:05













                        @Igal: Edited my answer to solve that issue, you should first use sudo -i before you source. Thanks for pointing that out.

                        – jobin
                        May 18 '14 at 18:06





                        @Igal: Edited my answer to solve that issue, you should first use sudo -i before you source. Thanks for pointing that out.

                        – jobin
                        May 18 '14 at 18:06













                        ok, pardon the newbie questions, but how do I exit the sudo -i once I'vet called source? without exiting I am getting the original error message...

                        – isapir
                        May 18 '14 at 18:08





                        ok, pardon the newbie questions, but how do I exit the sudo -i once I'vet called source? without exiting I am getting the original error message...

                        – isapir
                        May 18 '14 at 18:08













                        @Igal: Just press Ctrl + d or type exit.

                        – jobin
                        May 18 '14 at 18:09






                        @Igal: Just press Ctrl + d or type exit.

                        – jobin
                        May 18 '14 at 18:09












                        0














                        The solution I was looking for is in /etc/environment which, as specified at EnvironmentVariables, does not process scripts and does not expand variables, so adding the following (without export) did the trick:



                        JAVA_HOME=/opt/java/jdk1.8.0_05


                        Then I rebooted the system for the changes to take affect.






                        share|improve this answer



























                          0














                          The solution I was looking for is in /etc/environment which, as specified at EnvironmentVariables, does not process scripts and does not expand variables, so adding the following (without export) did the trick:



                          JAVA_HOME=/opt/java/jdk1.8.0_05


                          Then I rebooted the system for the changes to take affect.






                          share|improve this answer

























                            0












                            0








                            0







                            The solution I was looking for is in /etc/environment which, as specified at EnvironmentVariables, does not process scripts and does not expand variables, so adding the following (without export) did the trick:



                            JAVA_HOME=/opt/java/jdk1.8.0_05


                            Then I rebooted the system for the changes to take affect.






                            share|improve this answer













                            The solution I was looking for is in /etc/environment which, as specified at EnvironmentVariables, does not process scripts and does not expand variables, so adding the following (without export) did the trick:



                            JAVA_HOME=/opt/java/jdk1.8.0_05


                            Then I rebooted the system for the changes to take affect.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 18 '14 at 22:59









                            isapirisapir

                            183129




                            183129





















                                0














                                I added JAVA_HOME in tomcat7.service script as setenv.sh was not get sourced by catalina.sh



                                Steps:



                                1.Open tomcat7 service script file



                                sudo gedit /etc/init.d/tomcat7



                                2.Set JAVA_HOME



                                .
                                .
                                .
                                JAVA_HOME=/usr/lib/jvm/java-8-oracle

                                # Directory where the Tomcat 6 binary distribution resides
                                CATALINA_HOME=/usr/share/$NAME

                                # Directory for per-instance configuration files and webapps
                                CATALINA_BASE=/var/lib/$NAME

                                # Use the Java security manager? (yes/no)
                                TOMCAT7_SECURITY=no


                                3.Start tomcat7 service



                                sudo service tomcat7 status






                                share|improve this answer








                                New contributor




                                CᴴᴀZ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.
























                                  0














                                  I added JAVA_HOME in tomcat7.service script as setenv.sh was not get sourced by catalina.sh



                                  Steps:



                                  1.Open tomcat7 service script file



                                  sudo gedit /etc/init.d/tomcat7



                                  2.Set JAVA_HOME



                                  .
                                  .
                                  .
                                  JAVA_HOME=/usr/lib/jvm/java-8-oracle

                                  # Directory where the Tomcat 6 binary distribution resides
                                  CATALINA_HOME=/usr/share/$NAME

                                  # Directory for per-instance configuration files and webapps
                                  CATALINA_BASE=/var/lib/$NAME

                                  # Use the Java security manager? (yes/no)
                                  TOMCAT7_SECURITY=no


                                  3.Start tomcat7 service



                                  sudo service tomcat7 status






                                  share|improve this answer








                                  New contributor




                                  CᴴᴀZ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                  Check out our Code of Conduct.






















                                    0












                                    0








                                    0







                                    I added JAVA_HOME in tomcat7.service script as setenv.sh was not get sourced by catalina.sh



                                    Steps:



                                    1.Open tomcat7 service script file



                                    sudo gedit /etc/init.d/tomcat7



                                    2.Set JAVA_HOME



                                    .
                                    .
                                    .
                                    JAVA_HOME=/usr/lib/jvm/java-8-oracle

                                    # Directory where the Tomcat 6 binary distribution resides
                                    CATALINA_HOME=/usr/share/$NAME

                                    # Directory for per-instance configuration files and webapps
                                    CATALINA_BASE=/var/lib/$NAME

                                    # Use the Java security manager? (yes/no)
                                    TOMCAT7_SECURITY=no


                                    3.Start tomcat7 service



                                    sudo service tomcat7 status






                                    share|improve this answer








                                    New contributor




                                    CᴴᴀZ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.










                                    I added JAVA_HOME in tomcat7.service script as setenv.sh was not get sourced by catalina.sh



                                    Steps:



                                    1.Open tomcat7 service script file



                                    sudo gedit /etc/init.d/tomcat7



                                    2.Set JAVA_HOME



                                    .
                                    .
                                    .
                                    JAVA_HOME=/usr/lib/jvm/java-8-oracle

                                    # Directory where the Tomcat 6 binary distribution resides
                                    CATALINA_HOME=/usr/share/$NAME

                                    # Directory for per-instance configuration files and webapps
                                    CATALINA_BASE=/var/lib/$NAME

                                    # Use the Java security manager? (yes/no)
                                    TOMCAT7_SECURITY=no


                                    3.Start tomcat7 service



                                    sudo service tomcat7 status







                                    share|improve this answer








                                    New contributor




                                    CᴴᴀZ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    share|improve this answer



                                    share|improve this answer






                                    New contributor




                                    CᴴᴀZ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    answered 10 mins ago









                                    CᴴᴀZCᴴᴀZ

                                    11




                                    11




                                    New contributor




                                    CᴴᴀZ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.





                                    New contributor





                                    CᴴᴀZ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.






                                    CᴴᴀZ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.



























                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Ask Ubuntu!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f468772%2ftomcat-does-not-recognize-java-home%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Möglingen Índice Localización Historia Demografía Referencias Enlaces externos Menú de navegación48°53′18″N 9°07′45″E / 48.888333333333, 9.129166666666748°53′18″N 9°07′45″E / 48.888333333333, 9.1291666666667Sitio web oficial Mapa de Möglingen«Gemeinden in Deutschland nach Fläche, Bevölkerung und Postleitzahl am 30.09.2016»Möglingen

                                        Virtualbox - Configuration error: Querying “UUID” failed (VERR_CFGM_VALUE_NOT_FOUND)“VERR_SUPLIB_WORLD_WRITABLE” error when trying to installing OS in virtualboxVirtual Box Kernel errorFailed to open a seesion for the virtual machineFailed to open a session for the virtual machineUbuntu 14.04 LTS Virtualbox errorcan't use VM VirtualBoxusing virtualboxI can't run Linux-64 Bit on VirtualBoxUnable to insert the virtual optical disk (VBoxguestaddition) in virtual machine for ubuntu server in win 10VirtuaBox in Ubuntu 18.04 Issues with Win10.ISO Installation

                                        Antonio De Lisio Carrera Referencias Menú de navegación«Caracas: evolución relacional multipleja»«Cuando los gobiernos subestiman a las localidades: L a Iniciativa para la Integración de la Infraestructura Regional Suramericana (IIRSA) en la frontera Colombo-Venezolana»«Maestría en Planificación Integral del Ambiente»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»«Conózcanos»«Caracas: evolución relacional multipleja»«La Metrópoli Caraqueña: Expansión Simplificadora o Articulación Diversificante»