Solved

How to set JAVA_HOME in linux

Posted on 2014-01-13
10
594 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

724 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