CentOS7 use the Yum command to install Java Jdk1.8__java

Source: Internet
Author: User
view Self-brought Java information

[Root@zck ~]# Java-version
Java Version "1.7.0_"
OpenJDK Runtime Environment (IcedTea6 1.11.1) (rhel-1.45.1.11.1.el6-x86_64)
OpenJDK 64-bit Server VM (build 20.0-b12, Mixed mode) to further view JDK information:

[Root@localhost ~]# Rpm-qa | grep java
Javapackages-tools-3.4.1-6.el7_0.noarch
Tzdata-java-2014i-1.el7.noarch
Java-1.7.0-openjdk-headless-1.7.0.71-2.5.3.1.el7_0.x86_64
Java-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64
Python-javapackages-3.4.1-6.el7_0.noarch Uninstall OpenJDK, do the following:

[Root@localhost ~]# rpm-e–nodeps Tzdata-java-2014i-1.el7.noarch
[Root@localhost ~]# rpm-e–nodeps java-1.7.0-openjdk-headless-1.7.0.71-2.5.3.1.el7_0.x86_64
[Root@localhost ~]# rpm-e–nodeps java-1.7.0-openjdk-1.7.0.71-2.5.3.1.el7_0.x86_64

Rpm-e–nodeps Tzdata-java-2017b-1.el7.noarch
Rpm-e–nodeps java-1.7.0-openjdk-1.7.0.141-2.6.10.1.el7_3.x86_64
Rpm-e–nodeps java-1.7.0-openjdk-headless-1.7.0.141-2.6.10.1.el7_3.x86_64

Rpm-e–nodeps Tzdata-java-2017b-1.el7.noarch
Rpm-e–nodeps java-1.8.0-openjdk-headless-1.8.0.141-1.b16.el7_3.x86_64
Rpm-e–nodeps java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64 installation mode: 1, enter the following command to view the list of available JDK packages;

Yum Search Java | Grep-i–color JDK 2, installing the JAVA SDK on CentOS Linux

At the command line terminal, enter the following command with root user yum install Opensdk:

Yum Install java-1.8.0-openjdk java-1.8.0-openjdk-devel #安装openjdk

The completion of the above command indicates that the JDK installation was successful. 3. Set up java_home environment variable on CentOS Linux (java_home environment variable)

After Rhel and CentOS Linux use the yum command, install OPENSDK to the/usr/lib/jvm/directory:

4, with the CD command into the JVM under the only directory java-1.8.0-openjdk-1.8.0.51.x86_64, and jre-1.8.0-openjdk.x86_64 this link is to point to Java-1.8.0-openjdk-1.8.0.51.x86_64 This folder, so you can directly use the Export command to point java_home to jre-1.8.0-openjdk.x86_64 this link.
Even with the Export command:

Export java_home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51.x86_64

However, this can only be effective in the current session, once the log off, the failure. 5, the standard way to configure environment variables

Do the following:

Vi/etc/profile

Paste the following three lines into the/etc/profile:
Export java_home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.51.x86_64
Export classpath=.: javahome/jre/lib/rt.jar:java_home/jre/lib/rt.jar:java_home/lib/dt.jar:javahome/lib/ Tools.jarexportpath= Java_home/lib/tools.jar export Path=path: $JAVA _home/bin

Save shutdown, after execution: Source/etc/profile #让设置立即生效.

Verify that the three variables are set to what we want by entering the following command:

[root@~]# Echo Java_home
[root@ ~]# echojava_home [root@ ~]# Echo CLASSPATH
[Root@ ~]# Echo $PATH

echo $JAVA _home
echo $CLASSPATH echo
$PATH
Export java_home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64
export classpath=.: $JAVA _home/ Jre/lib/rt.jar: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar
export path= $PATH: $JAVA _home/bin

# Reboot reboot machine configuration takes effect
or execute the following command to take effect immediately

Source/etc/profile

There are two JDK when configuring Java_home it was very depressing to pick a random one, question a
Source/etc/profile run times wrong question two but no effect javac that's weird

Etc/profile:fork:cannot Allocate Memory
etc/profile:line 80:export: ' java-1.8.0-openjdk ': not a valid identifier
6, test whether the installation of Java configuration Success

To view the Java version, enter the command:
[root@~]# java-version

7, the creation of a Java applet test, named Helloworld.java, enter the following command:
[root@ ~]# Touch Helloworld.java

Copy the following code into Helloworld.java:

public class HelloWorld {public
        static void Main (string[] args) {
            System.out.println ("Hello, world! This is a test code by nixcraft! ");
        }
    

After you copy it in, save the closing file. Compile and run this applet and enter the following command:
[root@ ~]# Javac Helloworld.java
[root@ ~]# Java HelloWorld

Will get the following display:
Hello, world!. This is a test code by nixcraft!
8. How (how) to run. Java applications such as jars.

The syntax is as follows:
[root@~]# Java-jar File.jar
[root@~]# Java-jar/path/to/my/java/app.jar #/path/to/my/java/app.jar represents the path of the application
[root@ ~]# Java-jar/path/to/my/java/app.jar arg1 arg2 # arg1 represents parameter 1, arg2 represents parameter 2

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.