[Go] Java Learning--ubuntu installation of JDK and configuration of Java environment

Source: Internet
Author: User
Tags gz file java se

Reprinted from http://blog.csdn.net/hcbbt/article/details/11817697

first step, download

To download the JDK on the official website,in the Java SE Development Kit 7uXX, the Accept License agreement tick, so as to download the JDK, and then we choose the corresponding version of Ubuntu download, if you do not know which version of the next , can use getconf long_bit see oneself is several.

my virtual machine inside Ubuntu is 32-bit, here I download the version is jdk-7u40-linux-i586.tar.gz, the following are installed in this version, if the download is a higher version or 64-bit files, please modify the command yourself. more than 130 m stuff, during the download we can go busy with something else. The second step, unzip the compressed packageCreate a directory Java under/usr/local/: [Plain]View Plaincopyprint?
    1. sudo mkdir/usr/local/java
of course, you can follow your own custom to create a directory, but the following command to change the contents of the inside. copy the downloaded. tar.gz file to this directory, note that the file operation under/usr/local here requires root permission, so it cannot be copied in the File manager, so we enter the directory where the JDK resides in the terminal and execute: [Plain]View Plaincopyprint?
    1. sudo cp Jdk-7u40-linux-i586.tar.gz/usr/local/java
then unzip the compressed package: [Plain]View Plaincopyprint?
    1. Cd/usr/local/java
    2. sudo tar-zxvf jdk-7u40-linux-i586.tar.gz
after a brush screen if you do not see the error and other words that the decompression succeeded, if there is an error, please see if the compression package is complete. The third step, configurationmodify the. bashrc file: [Plain]View Plaincopyprint?
    1. sudo vim ~/.BASHRC
Add in the following: [Plain]View Plaincopyprint?
    1. #java
    2. Export java_home=/usr/local/java/jdk1.7.0_40
    3. Export JRE_HOME=/USR/LOCAL/JAVA/JDK1.7.0_40/JRE
    4. Export classpath=.: $JAVA _home/lib: $JRE _home/lib
    5. Export Path=/usr/local/java/jdk1.7.0_40/bin: $PATH

then let the changes take effect [Plain]View Plaincopyprint?
    1. SOURCE ~/.BASHRC

the next is to configure the default JDK: [Plain]View Plaincopyprint?
    1. sudo update-alternatives--install/usr/bin/java Java/usr/local/java/jdk1.7.0_40/bin/java 300
    2. sudo update-alternatives--install/usr/bin/javac Javac/usr/local/java/jdk1.7.0_40/bin/javac 300
    3. sudo update-alternatives--install/usr/bin/javap JAVAP/USR/LOCAL/JAVA/JDK1.7.0_40/BIN/JAVAP 300
    4. sudo update-alternatives--install/usr/bin/javadoc javadoc/usr/local/java/jdk1.7.0_40/bin/javadoc 300

The third step, inspectionExecutive Java-versionThe return information should be as follows: [Plain]View Plaincopyprint?
    1. Java Version "1.7.0_40"
    2. Java (TM) SE Runtime Environment (build 1.7.0_40-b43)
    3. Java HotSpot (TM) Server VM (build 24.0-b56, Mixed mode)


then we can write a simple Java test: [Java]View Plaincopyprint?
    1. Class helloworld{
    2. public static void Main (String [] arguments) {
    3. System.out.println ("Hello world!");
    4. System.out.println ("Test successly!");
    5. }
    6. }

Execution [Plain]View Plaincopyprint?
      1. Javac Test.java Compiling files
      2. Java HelloWorld Execution

[Go] Java Learning--ubuntu installation of JDK and configuration of Java environment

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.