Installation of the JDK under Ubuntu and configuration of the Java environment

Source: Internet
Author: User
Tags gz file java se

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, can use getconf long_bit see oneself is several.

The second step, unzip the compressed packageCreate a directory Java under/usr/local/:

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:

sudo cp Jdk-7u40-linux-i586.tar.gz/usr/local/java

Then unzip the compressed package:

Cd/usr/local/java

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:

sudo vim ~/.BASHRC

Add in the following:

#java

Export java_home=/usr/local/java/jdk1.7.0_40

Export JRE_HOME=/USR/LOCAL/JAVA/JDK1.7.0_40/JRE

Export classpath=.: $JAVA _home/lib: $JRE _home/lib

Export Path=/usr/local/java/jdk1.7.0_40/bin: $PATH

Then let the changes take effect

SOURCE ~/.BASHRC

The next is to configure the default JDK:

sudo update-alternatives--install/usr/bin/java Java/usr/local/java/jdk1.7.0_40/bin/java 300

sudo update-alternatives--install/usr/bin/javac Javac/usr/local/java/jdk1.7.0_40/bin/javac 300

sudo update-alternatives--install/usr/bin/javap JAVAP/USR/LOCAL/JAVA/JDK1.7.0_40/BIN/JAVAP 300

sudo update-alternatives--install/usr/bin/javadoc javadoc/usr/local/java/jdk1.7.0_40/bin/javadoc 300

The third step, inspectionThe execution java-version return information should be as follows:

Java Version "1.7.0_40"

Java (TM) SE Runtime Environment (build 1.7.0_40-b43)

Java HotSpot (TM) Server VM (build 24.0-b56, Mixed mode)

Then we can write a simple Java test:class helloworld{public static void Main (String [] arguments) {     System.out.println ("Hello world!");     System.out.println ("Test successly!");   }} executes

Javac Test.java Compiling files

Java HelloWorld Execution

At this point, the JDK environment is configured to complete ...

Installation of the JDK under Ubuntu and configuration of the 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.