Install JDK 7 in centos

Source: Internet
Author: User

Install JDK 7 in centos
Preface:
Java is an object-oriented programming language that can write cross-platform application software. It is a Java programming language and Java platform (JavaEE (j2ee) launched by Sun Microsystems in May 1995 ), A general term for JavaME (j2se) and JavaSE (j2se. Since its launch, Java has become very popular and has developed rapidly, which has a powerful impact on the C ++ language. Java has excellent versatility, efficiency, platform portability and security. It is widely used in personal PCs, data centers, game consoles, scientific supercomputers, mobile phones and the Internet, it also has the largest developer community in the world.




Hadoop requires jdk support. Therefore, you must first prepare the jdk environment on the linux system. The detailed steps are as follows:

1. Download the JDK installation package
Installation version: jdk-7u60-linux-x64.gz
: Http://yun.baidu.com/share/link? Consumer id = 1769428623 & uk = 103052787
View latest: http://www.oracle.com/technetwork/java/javase/downloads/index.html


2. Unzip and install
Install JDK to this path:/usr/lib/jvm
If this directory does not exist (of course not exist for the first time), we will create a new directory.
Cd/usr/lib
Sudo mkdir jvm
Sudo tar zxvf./jdk-7u60-linux-x64.tar.gz-C/usr/lib/jvm

After the creation, we will go to the directory of the downloaded compressed package, decompress it to the folder we just created, and modify the name to facilitate our management.
Sudo tar zxvf/root/jdk-7u25-linux-i586.tar.gz-C/usr/lib/jvm
Cd/usr/lib/jvm
Sudo mv jdk1.7.0 _ 25/jdk7

View the result:
[Root @ name01 jdk1.7.0 _ 60] # cd/usr/lib/jvm/
[Root @ name01 jvm] # ll
Total 4
Drwxr-xr-x. 8 uucp 143 4096 May 7 jdk1.7.0 _ 60
[Root @ name01 jvm] # cd jdk1.7.0 _ 60/
[Root @ name01 jdk1.7.0 _ 60] #
[Root @ name01 jdk1.7.0 _ 60] # ll
Total 19776
Drwxr-xr-x. 2 uucp 143 4096 May 7 bin
-R --. 1 uucp 143 3339 May 7 COPYRIGHT
Drwxr-xr-x. 4 uucp 143 4096 May 7 db
Drwxr-xr-x. 3 uucp 143 4096 May 7 include
Drwxr-xr-x. 5 uucp 143 4096 May 7 jre
Drwxr-xr-x. 5 uucp 143 4096 May 7 lib
-R --. 1 uucp 143 40 May 7 LICENSE
Drwxr-xr-x. 4 uucp 143 4096 May 7 man
-R --. 1 uucp 143 114 May 7 README.html
-Rw-r --. 1 uucp 143 499 May 7 release
-Rw-r --. 1 uucp 143 19903556 May 7 src.zip
-Rw-r --. 1 uucp 143 123324 Apr 29 THIRDPARTYLICENSEREADME-JAVAFX.txt
-R --. 1 uucp 143 173559 May 7 THIRDPARTYLICENSEREADME.txt


3. Configure Environment Variables
(1) only valid for the current user
Vim ~ /. Bashrc
Export JAVA_HOME =/usr/lib/jvm/jdk1.7.0 _ 60
Export JRE_HOME =$ {JAVA_HOME}/jre
Export CLASSPATH =. :$ {JAVA_HOME}/lib :$ {JRE_HOME}/lib
Export PATH =$ {JAVA_HOME}/bin: $ PATH

Save and exit, and then enter the following command to make it take effect
Source ~ /. Bashrc

(2) effective for all users
Vim/etc/profile
Export JAVA_HOME =/usr/lib/jvm/jdk1.7.0 _ 60
Export JRE_HOME =$ {JAVA_HOME}/jre
Export CLASSPATH =. :$ {JAVA_HOME}/lib :$ {JRE_HOME}/lib
Export PATH =$ {JAVA_HOME}/bin: $ PATH

Save and exit, and then enter the following command to make it take effect
Source/etc/profile


4. Configure the default JDK (this step can be omitted in general)
The default JDK exists in some Linux distributions, such as OpenJDK. So in order to make the installed JDK version become the default JDK version, we need to make the following configuration.
Run the following command:
Sudo update-alternatives -- install/usr/bin/java/usr/lib/jvm/jdk1.7.0 _ 60/bin/java 300
Sudo update-alternatives -- install/usr/bin/javac/usr/lib/jvm/jdk1.7.0 _ 60/bin/javac 300
Note: If the above two commands fail to find the path, restart the machine and repeat the above two lines of code.

Run the following code to view the current JDK versions and configurations:
Sudo update-alternatives -- config java


5. Test
In the linux Command Line, use java-version and javac-version to view the java version. The result is as follows:

[Root @ name01 jdk1.7.0 _ 60] # java-version
Java version "1.7.0 _ 60"
Java (TM) SE Runtime Environment (build 1.7.0 _ 60-b19)
Java HotSpot (TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
[Root @ name01 jdk1.7.0 _ 60] #

[Root @ name01 jdk1.7.0 _ 60] # javac-version
Javac 1.7.0 _ 60
[Root @ name01 jdk1.7.0 _ 60] #


6. java code Testing
Write a simple java Test class Test. java and compile and run the java program as follows:
[Root @ name01 tim] # vim Test. java
Public class test {
Public static void main (String args []) {
System. out. println ("A new jdk test! ");
}
}
Save and exit, compile the Test class
[Root @ name01 tim] # javac Test. java
Test. java: 1: error: class test is public, shocould be declared in a file named test. java
Public class test {
^
1 error
If an error is reported, the class name and java file name must be unified. Otherwise, compilation will fail.
[Root @ name01 tim] # vim Test. java

Public class Test {
Public static void main (String args []) {
System. out. println ("A new jdk test! ");
}
}
Save and exit, and then compile
[Root @ name01 tim] # javac Test. java
[Root @ name01 tim] #
[Root @ name01 tim] # ll Test *
-Rw-r --. 1 root 418 Aug 22 Test. class
-Rw-r --. 1 root 114 Aug 22 Test. java
[Root @ name01 tim] #
After compilation is successful, the Test. class executable file is added and the execution result is displayed as follows:
[Root @ name01 tim] # java Test
A new jdk test!
[Root @ name01 tim] #

When the jdk runs normally, the result indicates that the java command is ready to run. Now, the jdk is fully deployed in the linux environment.



An error occurred while installing JDK 7 in linux.

Are you a 64-bit system or a 32-bit system?

In linux, how does one set up a web server? The system is centos62, which supports php jsp asp mysql

The server built in LINUX cannot support ASP.
Install apache

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.