1. Introduction
This article will show you how to install different versions of Java under Ubuntu using Apt-get.
2. Install the default JRE/JDK
This is the simplest method, (original Openjdk6→ubuntu12.04,open ' jdk6→ubuntu12.10+)
Update package List
sudo apt-get update
Check if Java is already installed
Java-version
If it is not installed, continue. (This step installs the JRE, which can be skipped – Translator's note )
sudo apt-get install Default-jre
Installing the JDK
sudo apt-get install DEFAULT-JDK
Installation complete (can be java -version
detected again)
3. Install OpenJDK7 (optional)
4. Installing an Oracle JDK (optional)
Oracle JDK is an official JDK, but Oracle no longer provides default installation for Ubuntu.
5. Managing Java (optional)
If you have multiple versions of Java installed, modifying the default Java version can be done in the following ways:
sudo update-alternatives–config java
If you have 2 or more Java installed, the following message appears:
| Section
Path |
| Priority
Status |
*0 |
/usr/lib/jvm/java-7-oracle/jre/bin/java |
1062 |
AutoMode |
1 |
/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java |
1061 |
Manual mode |
2 |
/usr/lib/jvm/java-7-oracle/jre/bin/java |
1062 |
Manual mode |
* Results from the original
Selection |
Path |
| Priority
Status |
*0 |
/usr/lib/jvm/java-7-oracle/jre/bin/java |
2 |
Auto mode |
1 |
/usr/lib/jvm/java-7-oracle/jre/bin/java |
2 |
Manual mode |
2 |
/usr/lib/jvm/java-8-oracle/jre/bin/java |
1 |
Manual mode |
Press ENTER to keep the current choice[*], or type selection number:
* Results of the machine running
You can now select a corresponding version of the number as the default Java version
You can do the same for the Java compiler
sudo updata-alternatives–config javac
The same method can be used for other multi-version commands, including but not limited to (Keytool, Javadoc jarsigner) in Java
6. Set the environment variable Java_home
First, find the installation path for Java
sudo update-alternatives–config java
The returned results are shown in the two table above, and the path is also visible at a glance.
Select one, copy, and then modify/etc/environment:
sudo nano/etc/environment
Add a line to the open file as follows (the path that replaces the Your_path with the powertrain copy):
Java_home= "Your_path"
Now reload this file.
Source/etc/environment
Test with the following command:
Echo $JAVA _home
If you are returning exactly the path you just set up, then congratulations on your setup success, otherwise, make sure you follow the above procedure.
Install and manage Java with Apt-get under Ubuntu