?
Solved

How to set JAVA_HOME in linux

Posted on 2014-01-13
10
Medium Priority
?
731 Views
Last Modified: 2014-01-13
How to set JAVA_HOME  in  Red Hat  Enterprise Linux Server Release 5.5 ?

Which files to edit ?

Please tell me the steps .
0
Comment
Question by:cofactor
  • 5
  • 5
10 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39776060
To set it for all users use /etc/profile, to set it for a particular user use the .bashrc file in the user's HOME directory to add

export JAVA_HOME=/path/to/java/home

Don't forget to logout and re-login.
0
 

Author Comment

by:cofactor
ID: 39776202
I am bit confused .

When I  run this  I get  

# whereis javac
javac: /usr/bin/javac


and ..

# java -version
java version "1.6.0"
OpenJDK  Runtime Environment (build 1.6.0-b09)
OpenJDK Client VM (build 1.6.0-b09, mixed mode)


]# whereis java
java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java /usr/share/man/man1/java.1.gz


Can you please tell what to  I put in  $JAVA_HOME ?
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 1600 total points
ID: 39776285
Try

/usr/sbin/alternatives --config java
/usr/sbin/alternatives --config javac

Do you get an reply saying that there are programs providing java/javac?

If you get one program you'll see the path to the respective executable.
If there is no "+" in front type the selection number "1", hit <Enter> and follow the instructions.
If you see several ones you have the option to choose which one to make the default, just like above.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:cofactor
ID: 39776286
I get this ...

/usr/sbin/alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
*+ 2           /usr/lib/jvm/jre-1.6.0-openjdk/bin/java




so I guess my  java home would be ...

JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk


right ?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39776294
So you have two java versions installed, and 1.6 is set as the default (I assume that's what you desire).

Yes, JAVA_HOME should be "/usr/lib/jvm/jre-1.6.0-openjdk" in this case.

You could type "2" and hit <Enter> and follow the instructions to set 1.6 as the default again. Maybe this will set JAVA_HOME, but if it doesn't see my first comment where to add it.

Best use /etc/profile, so all users will have the correct version as the default.
You should also check your PATH variable. Does it contain $JAVA_HOME/bin (the resolved version, that is, e.g. "/usr/lib/jvm/jre-1.6.0-openjdk/bin")? If it doesn't set it accordingly ir /etc/profile, too.
0
 

Author Comment

by:cofactor
ID: 39776308
I  have set this  now in  /etc/profile


JAVA_HOME="/usr/lib/jvm/jre-1.6.0-openjdk";
export JAVA_HOME;
#PATH=$JAVA_HOME/bin:$PATH;
#export PATH;
ANT_HOME="/opt/apache-ant-1.8.2";
export ANT_HOME;
PATH=$JAVA_HOME/bin:$PATH:$ANT_HOME/bin:$CATALINA_HOME/bin;
export CATALINA_HOME="/home/softwares/apache-tomcat-6.0.32";
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39776334
Since the PATH contains a reference to CATALINA_HOME you must set this variable before setting PATH (interchange the last two lines):

JAVA_HOME="/usr/lib/jvm/jre-1.6.0-openjdk";
export JAVA_HOME;
ANT_HOME="/opt/apache-ant-1.8.2";
export ANT_HOME;
CATALINA_HOME="/home/softwares/apache-tomcat-6.0.32";
export CATALINA_HOME
PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$CATALINA_HOME/bin:$PATH

For consistency use the same format of "export" in all cases. Because you used the format

VAR=value
export VAR

for JAVA_HOME and ANT_HOME I'd suggest using it for CATALINA_HOME as well (I admit, it's a matter of taste).

Your standard PATH should come after the JAVA/CATALINA/ANT paths, to avoid possible confusion.

Once these modifications are applied everything should be just fine. Don't forget to logout and re-login to make the changes effective for your shell session.
0
 

Author Comment

by:cofactor
ID: 39776351
This is working fine.   Thank you very much.

I have a small query  here .

What happens when we do export VAR ?
 Is not just  VAR=value  is enough to use  the variable later ?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39776368
"export" adds the specified variable to the environment, which means that it is made available to subprocesses of the calling shell.

Without "export" a variable is only available to your current session but not to scripts/programs called from that session.
0
 

Author Closing Comment

by:cofactor
ID: 39776524
Excellent
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
I have written articles previously comparing SARDU and YUMI.  I also included a couple of lines about Easy2boot (easy2boot.com).  I have now been using, and enjoying easy2boot as my sole multiboot utility for some years and realize that it deserves …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question