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?
- 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?
- sudo cp Jdk-7u40-linux-i586.tar.gz/usr/local/java
then unzip the compressed package:
[Plain]View Plaincopyprint?
- 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:
[Plain]View Plaincopyprint?
- sudo vim ~/.BASHRC
Add in the following:
[Plain]View Plaincopyprint?
- #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
[Plain]View Plaincopyprint?
- SOURCE ~/.BASHRC
the next is to configure the default JDK:
[Plain]View Plaincopyprint?
- 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, inspectionExecutive Java-versionThe return information should be as follows:
[Plain]View Plaincopyprint?
- 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:
[Java]View Plaincopyprint?
- Class helloworld{
- public static void Main (String [] arguments) {
- System.out.println ("Hello world!");
- System.out.println ("Test successly!");
- }
- }
Execution
[Plain]View Plaincopyprint?
- Javac Test.java Compiling files
- Java HelloWorld Execution
[Go] Java Learning--ubuntu installation of JDK and configuration of Java environment