1 using the source installation
Use the following command to install, just some time, it will download a lot of files, and you want to make sure that your network environment is good:
sudo add-apt-repository ppa:webupd8team/javasudo apt-get updatesudo apt-get install oracle-java8-installersudo apt-get install oracle-java8-set-default
If you want to install Java 8(i.e Java 1.8)
it, replace it in the command above java7
java8
.
2 Installing through the bin package
You can also install the common Bin package on Linux, download the official bin package, install the decompression under the terminal, and then modify the environment variable to point to the JDK
Select a different version as needed to download the bin package
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Unzip the downloaded jdk-8u101-linux-x64.tar.gz
file.
Use the following command to extract:
sudo tar zxvf ./jdk-8u101-linux-x64.tar.gz
To facilitate management, the extracted files can be moved to another folder, the author moved the file to the /usr/java/jdk1.8.0_101
directory.
To facilitate the next set of environment variables, change the folder to a shorter name-jdk1.8
3 Setting environment variables
Edit. bashrc file
JAVA_HOME=/usr/java/jdk1.8.0_101JRE_HOME=$JAVA_HOME/jreJAVA_BIN=$JAVA_HOME/binCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/libPATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/binexport JAVA_HOME JRE_HOME PATH CLASSPATH
If you installed using the source method, the default installation path is in /usr/lib/jvm/java-8-oracle
, and the corresponding Java_home is configured
JAVA_HOME=/usr/lib/jvm/java-8-oracle
In order for the changes to take effect immediately, execute the following command at the terminal:
source ~/.bashrc
4 Verification
With the above steps, the JDK is installed.
Enter the following command java -version
to verify that
Install Oracle JDK on Ubuntu