I keep getting java version 1.4.2 instead of any of the later versions
Type which java
to find out which directory java
is being picked up from. You probably need to correct your PATH. At the moment, you have /home/asimon/java/bin
on your PATH, which must be an old version of java. You should update it to /home/asimon/java/jdk1.6.0_22/bin
. The PATH variable would be present in $HOME/.profile
.
Also, note that if you execute ./java -version
it will use the java executable present in the current working directory, instead of searching the PATH for it.
JAVA_HOME and PATH are set but java -version still shows the old one
While it looks like your setup is correct, there are a few things to check:
- The output of
env
- specificallyPATH
. command -v java
tells you what?- Is there a
java
executable in$JAVA_HOME\bin
and does it have the execute bit set? If notchmod a+x java
it.
I trust you have source
'd your .profile
after adding/changing the JAVA_HOME
and PATH
?
Also, you can help yourself in future maintenance of your JDK installation by writing this instead:
export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=$JAVA_HOME/bin:$PATH
Then you only need to update one env variable when you setup the JDK installation.
Finally, you may need to run hash -r
to clear the Bash program cache. Other shells may need a similar command.
Cheers,
Java migration 1.4 version to higher versions
While you could download Java off the net, extract it and install it, you should stick to using your distribution's package manager in order to ensure proper version management and maintainability of your OS. Each Linux distribution has its own package manager (Debian uses apt
/dpkg
, Red Hat uses yum
and so forth), so you should familiarize yourself with the relevant package manager and take it from there.
(Also, positively consider @Thilo's advice about skipping 1.6.)
Different Java version showing on command line
It's possible to have many JRE side-by-side on a computer.
If the JRE is properly installed on Windows, informations about each version are stored in the registry. The installation process installs a special java.exe in the system PATH (%SYSTEMROOT%\System32). So you don't need to alter you PATH because this special java.exe will find the current JRE. From a command line, type java -version to display the current jre version installed.
With release 1.6, it's now possible to select a different JRE installation than the last one without any registry modification.
The JRE installation are listed in the registry in the key
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
Take this simple test class
public class ShowVersion {
public static void main(String args[]) {
System.out.println(System.getProperty("java.version"));
}
}
On a system, with 1.6 and 1.5 installed. If you type
> java ShowVersion
It's probably the 1.6 JRE that will be used since it's the last installed.
To force the 1.5 JRE instead, use this command line.
> java -version:"1.5" ShowVersion
If the bytecode is incompatible with the given JRE then .. it won't work, of course.
ref : technote java 6
You can always give the complete path to use a specific installation. Launching the JVM this way does not use the registry setting at all.
>"C:\Program Files\Java\j2re1.4.1_02\bin\java" -version
java version "1.4.1_02"
source : Select a particular JRE from the command line
Changed JAVA_HOME and PATH but java version remains the same
I think you did not configured your PATH
correctly, try export PATH=$JAVA_HOME/bin:$PATH
:
- Add
$JAVA_HOME/bin
to$PATH
, not$JAVA_HOME
, because the full path tojava
is$JAVA_HOME/bin/java
in the description of question. - Put your
$JAVA_HOME/bin
in the head of$PATH
, not the tail, otherwise the oldjava
in original$PATH
will always be found by shell first.
Related Topics
How to Schedule a Periodic Task in Java
How to Unzip Files Programmatically in Android
Replace String With Another in Java
How to Change a Jfreechart'S Size
Android Listview Selected Item Stay Highlighted
Find Where Java Class Is Loaded From
Java: How to Get a Class Literal from a Generic Type
Can You Use @Autowired With Static Fields
Java.Lang.Outofmemoryerror: Java Heap Space
Java.Lang.Numberformatexception: Invalid Double: " "
Limit Decimal Places in Android Edittext
Compound Class Names Are Not Supported Error in Webdriver
Understanding Metaspace Line in Jvm Heap Printout
Illegalargumentexception or Nullpointerexception For a Null Parameter
Java - How to Check Whether Another (Non-Java) Process Is Running on Linux