Before we go on to learn how to install Java, let's get a quick look at the differences between JRE, OPENJDK, and Oracle JDK.
JRE (Java Runtime Environment), which is the environment you normally need to run a Java-language application. If you are not a program member, these are enough for your needs.
The JDK represents the Java Development Toolkit, and if you want to do something about Java development (the reading program), that's exactly what you need.
OPENJDK is an open source implementation of the Java Development Toolkit, an official Oracle version of the Java Development Toolkit. Although OPENJDK is enough to satisfy most cases, many programs
For example, Android Studio recommends using Oracle JDK to avoid ui/performance problems.
Inspection
First, let's check if Java is installed on Ubuntu.
Open the terminal and use the following command:
Java-version
If you see output like the following, this means that you have not installed Java:
The program ' Java ' Can is found in the following packages:
* DEFAULT-JRE
* gcj-4.6-jre-headless * OPENJDK-6-JR
E-headless
* gcj-4.5-jre-headless
* openjdk-7-jre-headless
try:sudo apt-get Install
installation (1) command line installation
Installing the JRE on Ubuntu and Linux
Open the terminal and install the JRE using the following command:
sudo apt-get install Default-jre
Install OPENJDK on Ubuntu and Linux
At the terminal, use the following command to install the OPENJDK Java Development Kit:
sudo apt-get install DEFAULT-JDK
Specifically, if you want to install Java 7 or Java 6 and so on, you can use OPENJDK-7-JDK/OPENJDK-6JDK, but remember to install OPENJDK-7-JRE/OPENJDK-6-JRE before that.
Install the Oracle JDK on Ubuntu and Linux Mint using the following command to install, it will download a lot of files in just a few minutes, and you need to ensure that your network environment is good:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install Oracle-java8-installer
sudo apt-get install Oracle-java8-set-default
If you want to install Java 7 (i.e Java 1.7), replace JAVA8 with Java7 in the command above.
(2) Download compression package installation
1. Download JDK
Http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html
You can download the latest version of the JDK.
2. Unpack first
sudo tar zxvf./jdk-8u72-linux-x64.tar.gz
Then use MV to move to the directory you want to reach, such as:
MV jdk1.8.0_72 * * * * * (target location)
3. Setting Environment variables
Edit the. bashrc file.
Enter the following command at the terminal:
Vim ~/.BASHRC
At the end of the file, add the following lines of code:
Export JAVA_HOME=XXX (JDK installed directory)
export classpath=${java_home}/lib
export path=${java_home}/bin: $PATH
In order for the changes to take effect immediately, execute the following command at the terminal:
SOURCE ~/.BASHRC
See if there is any Java optional on this computer. The following commands are used here
sudo update-alternatives--list java
Because there may be other jdk in Ubuntu, such as OPENJDK, so in order to make use of the JDK we have installed by default, we have to do the following, using Update-alternatives to adjust the system default Java environment.
First Use update-alternatives--config Java to see the currently available JDK versions.
Update-alternatives--config Java There is only one
alternative in link Group Java (providing/usr/bin/java):/home/pi Aocoder/java/jdk1.8.0_66/bin nothing to
configure.
Then, you can use the following command to configure JDK1.8.0_72, which is actually to replace the jdk1.8.0_72 soft link jdk1.8.0_66, of course, Update-alternatives will
What candidate commands are recorded.
sudo update-alternatives --install /usr/bin/java java/home/piaocoder/java/jdk1.8.0_72/bin 2000
After that, it's OK:
sudo update-alternatives--config java
There are 2 choices for the alternative Java (Providing/usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /home/piaocoder/java/jdk1.8.0_72/bin Auto mode
1 /home/piaocoder/java/ Jdk1.8.0_66/bin 1888 manual mode
2 /home/piaocoder/java/jdk1.8.0_72/bin Manual mode
Now,/usr/bin/java has pointed to our jdk1.8.0_72.
If we want to remove the JDK environment we just added, execute the following code:
sudo update-alternatives--remove java/home/piaocoder/java/jdk1.8.0_72/bin
update-alternatives:using/ Home/piaocoder/java/jdk1.8.0_66/bin to Provide/usr/bin/java (Java) in Auto mode
Ll/usr/bin/java
lrwxrwxrwx 1 root July 2 12:02/usr/bin/java->/etc/alternatives/java/
ll/ Etc/alternatives/java
lrwxrwxrwx 1 root 17:45/etc/alternatives/java->/home/piaocoder/java/, July jdk1.8.0_66/bin/
--------------------------------------------------------------------------------------------------------------- -------
In addition, the path setting in/etc/profile can optionally overwrite or not overwrite the/usr/bin/java command.
If I set profile this way, I would use jdk1.8.0_66:
#set Java Environment
export java_home=/home/piaocoder/java/jdk1.8.0_66
export Classpath=${java_home}/lib
Export Path=${java_home}/bin: $PATH
If I set profile this way, I would use/usr/bin/java->/etc/alternatives/java:
#set Java Environment
export java_home=/home/piaocoder/java/jdk1.8.0_66
export Classpath=${java_home}/lib
Export Path=${java_home}/bin