How to install JDK8 under CentOS

Source: Internet
Author: User

Install the JDK on your centos machine today and find that the previous tutorials are old and many things are out of date. Write the feeling of installation today.

Determine if the installation

First, we have to determine whether the machine is installed JDK, many people recommend the use of the Java-version command. Using the java-version command on my computer, the contents are as follows:

Java Version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.2.el6_4-i386 u45-b15)
OpenJDK Server VM (build 24.45-b08, Mixed mode)

It looks as if the JDK is already installed in my machine, but when I use Javac, I get a hint:

-bash:javac:command not found

This means that the first Java command, not the Java command in the installed JDK, has a Java file that can be executed under all the paths of the $path, stating that the JDK is still not installed properly. Pay special attention to this.

Installing the JDK
    1. Go to http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html to download the installation files for the JDK. Since my Linux is 32 bits, I download the jdk-8u25-linux-i586.tar.gz file.
    2. Create a new/usr/java folder, place jdk-8u25-linux-i586.tar.gz in the folder, and switch the working directory to the/usr/java directory.
    3. Execute the command TAR-ZXVF jdk-8u25-linux-i586.gz decompression, decompression found/usr/java more than a jdk1.8.0_25 folder.
    4. With the above steps, the JDK is fully installed. The following is the configuration of the environment variable.

Configuring Environment variables
    1. Edit a profile using Vim/etc/profile
    2. At the bottom of the/etc/profile, add the following:

      Java_home=/usr/java/jdk1.8.0_25
      Path= $JAVA _home/bin: $PATH
      Classpath= $JAVA _home/jre/lib/ext: $JAVA _home/lib/tools.jar
      Export PATH java_home CLASSPATH

    3. Above, the environment variable configuration is complete. Note that the path in the configuration, it is necessary to put $java_home/bin in front , or use the Java command, the system will find the previous Java, do not look down. In this way, the JAVA executable file run directory is not $java_home/bin, and in other directories, will cause a lot of problems.
    4. Also note that the previous tutorial written classpath= $JAVA _home/lib.tools.jar, do not know what the previous version is, the current version is not such a jar package .
    5. Finally, use Source/etc/profile to make the profile effective immediately.
Command test
    1. Command not found error is not present with JAVAC commands
    2. Using Java-version, the version "1.8.0_25" appears in Java edition
    3. echo $JAVA _home, Echo $CLASSPATH, echo $PATH to see if your configuration is correct.
Code testing

Create a new file in your own working directory Hello.java, write the following:

 Public class hello{     publicstaticvoid  main (string[] args) {         System.out.println ( "Hello World");      } }

Execute the command below and if you get the following result, the JDK installation is complete.

[Email protected] ~/javaprojects/~/javaprojects/test]$ java-cp  . Hellohello World

Of course, we installed the JDK8, should test the characteristics of the JDK8. You can use the JDK8-specific stream to test the code as follows:

Importjava.util.Arrays;ImportJava.util.Iterator;Importjava.util.List;ImportJava.util.function.Consumer;Importjava.util.function.Function;Importjava.util.function.Predicate; Public classTestLambda1 { Public Static voidMain (string[] args) {//Aggregate Operationslist<string> myList = arrays.aslist ("Zhangsan", "Lisi", "Wangwu",                "Liuliu"); Mylist.stream (). Filter (xX.contains ("a")). Map (X-x.touppercase ()). ForEach (x-System.out.println (x)); }}

Run with the following command to get the results, stating that there is no problem with the installation.

[Email protected] ~/javaprojects/~/javaprojects/test]$ java-cp  . Testlambdazhangsanwangwu

How to install JDK8 under CentOS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.