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
Solved

How to set JAVA_HOME in linux

Posted on 2014-01-13
10
575 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb entity bean example 2 17
PHP error function not working on AWS 10 72
Java class and jar 3 25
WordPress: Debugging from my Windows 10 Desktop 6 36
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…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
This video teaches viewers about errors in exception handling.
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.

828 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