Java Version Still Showing as 1.4 Linux

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:

  1. The output of env - specifically PATH.
  2. command -v java tells you what?
  3. Is there a java executable in $JAVA_HOME\bin and does it have the execute bit set? If not chmod 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 to java 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 old java in original $PATH will always be found by shell first.


Related Topics



Leave a reply



Submit