Depending on your distribution it may be easiest to install from your package manager. On Ubuntu, for example, you can do:
Copysudo aptitude install open-jdk
Otherwise, usually the sun (oracle) version of java comes with a .bin file which you need to make executable and run as root in order to get java properly installed.
You shouldn't need to set any environment variables to get java to work, although some applications will require you to set JAVA_HOME, JDK_HOME and/or JRE_HOME to point to the java install's bin directory. You can see where your java install is by looking at where the symlink from
Copy/etc/alternatives/java
points.
Answer from Richard J on Stack OverflowDepending on your distribution it may be easiest to install from your package manager. On Ubuntu, for example, you can do:
Copysudo aptitude install open-jdk
Otherwise, usually the sun (oracle) version of java comes with a .bin file which you need to make executable and run as root in order to get java properly installed.
You shouldn't need to set any environment variables to get java to work, although some applications will require you to set JAVA_HOME, JDK_HOME and/or JRE_HOME to point to the java install's bin directory. You can see where your java install is by looking at where the symlink from
Copy/etc/alternatives/java
points.
Most Linux systems use the Gnu Java implementation by default and don't change this if you install an additional JDK. Therefore you need to explicitly make your new Java installation the default Java to be used. You can do so by running sudo update-alternatives --config java.
If you prefer graphical configuration, you can install the "galternatives" package, which lets you configure all those application defaults in a nice little UI.
Videos
The name of the control panel is different depending on whether you are using the Oracle JDK or OpenJDK.
Search for "control panel" in the dash. If you're using the Oracle JDK, you'll see the Oracle Java 7 Plugin Control Panel. If you're using OpenJDK, you'll see the Iced Tea Web Control Panel.
Search for "java" in dash and it will show java control panel. Images from what it shows when started:




Feel free to use this as a reference to tinkering with Java at runtime.
Choosing your JRE
To choose your JRE, use
sudo update-alternatives --config java
This will give something like the following output.
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
* 1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
3 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1051 manual mode
You can then select which Java runtime you want through the number selection.
Choosing your JVM
Sun/Oracle have two JVM choices, -server and -client. If you select the OpenJDK as your Java runtime environment you have additional options.
When you type java into the terminal with no other parameters, the help lists several optional VMs. I'm not sure which ones come with OpenJDK but 3 popular ones are JamVM, Zero and Cacao
To use these, simply type
java -jamvm 'your other parameters here'
java -cacao 'your other parameters here'
java -zero 'your other parameters here'
java -server 'your other parameters here
The -server VM is normally the default. You can also specify -client but in 64-bit IcedTea6 it appears to run the same version as -server.
There are most likely others but I find the default option to be the most responsive.
Setting your Memory
Finally, how to set the memory of Java (just because)
java -Xmx1024m -Xms128m 'your other parameters here'
This limits the memory allowed for the Java program to a maximum of 1024 MB, and sets its initial memory size to 128 MB. This is a great way of defining minimum system requirements. The Java 6 man page for the java command describes these options and others.
That's all. If anyone has additional Java tweaks for Ubuntu then leave them in the comments and I'll add them.
To set the default JVM inside an OpenJDK installation you need to edit the jvm.cfg configuration file located inside the /usr/lib/jvm/java-version-openjdk-arch/jre/lib/arch/jvm.cfg
Ubuntu expose the jvm.cfg file inside the /etc/ directory depending on OpenJDK version. /etc/java-6-openjdk/jvm-arch.cfg or /etc/java-7-openjdk/jvm-arch.cfg
The top most -jvmname KNOWN line inside the jvm.cfg file determine the default JVM.
There is no configuration tool available thus you have to locate and edit these files manually.
find /usr/lib/jvm/java-1.x.x-openjdkvim /etc/profilePrepend sudo if logged in as not-privileged user, ie.
sudo vim- Press 'i' to get in insert mode
add:
export JAVA_HOME="path that you found" export PATH=$JAVA_HOME/bin:$PATH- logout and login again, reboot, or use
source /etc/profileto apply changes immediately in your current shell
For all users, I would recommend creating a file in /etc/profile.d/java_home.sh the following lines
# Set JDK installation directory according to selected Java compiler
export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
This will update dynamically and works well with the alternatives system. Do note though that the update will only take place in a new login shell.
Re your first question:
possibly you may be confusing that the webupd8 script is 0.5b. That is the version of the script - it doesnt refer to the java version.
Further to the setting of the javac version.
I suspect you need to explicitly give the path of the javac compiler
i.e.
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-6.31-oracle/bin/javac" 1
followed by:
sudo update-alternatives --config javac
With regards to setting up the java chrome plugin.
The master question:
How do I install Oracle JDK 6?
includes this information - since your folder structure is slightly different your link command should be:
ln -s /usr/lib/jvm/java-6.31-oracle/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/
See this; run
sudo update-java-alternatives --list
to list off all the Java installations on a machine by name and directory, and then run
sudo update-java-alternatives --set [JDK/JRE name e.g. java-8-oracle]
to choose which JRE/JDK to use.
If you want to use different JDKs/JREs for each Java task, you can run update-alternatives to configure one java executable at a time; you can run
sudo update-alternatives --config java[Tab]
to see the Java commands that can be configured (java, javac, javah, javaws, etc). And then
sudo update-alternatives --config [javac|java|javadoc|etc.]
will associate that Java task/command to a particular JDK/JRE.
You may also need to set JAVA_HOME for some applications: from this answer you can use
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
for JREs, or
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:jre/bin/java::")
for JDKs.