Solved

How to set JAVA_HOME in linux

Posted on 2014-01-13
10
566 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 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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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 …

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now