Install JDK 7 in Ubuntu 12.04 ------------ be especially careful when configuring environment variables. The permissions in Ubuntu are a little strict.
Today, I want to download the source code of an android system.
It is easy to download the source code, so I plan to configure an environment in my newly installed Linux virtual machine,
The result is a half-day shell allocated by a JDK. Finally, I saw the following information:
1
@-Virtualbox :~ $ Java-version
2
Java version "1.7.0 _ 07"
3
Java (TM) se Runtime Environment (build 1.7.0 _ 07-b10)
4
Java hotspot (TM) Client VM (build 23.3-b01, mixed mode)
To avoid detours in the future, it is also a learning note. I will write down the configuration process.
Download jdk7 www.2cto.com
Download the latest JDK 7 from the official Oracle website. Currently the latest is: jdk-7u7-linux-i586.tar.gz
Unzip and install
I installed JDK in/opt/Java, so the following code is executed in the terminal window:
1
Sudo mkdir/opt/Java
2
Sudo tar zxvf/home/David/downloads/jdk-7u7-linux-i586.tar.gz-C/opt/Java
Modify Environment Variables
If you are using the root account to log on, you can modify it as follows:
1. Open/etc/environment in the editor.
1
Gedit/etc/environment
2. Modify the file
Www.2cto.com
1
Path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: usr/games: $ {java_home}/bin"
2
Java_home =/opt/Java/jdk1.7.0 _ 07
3
Jre_home =$ {java_home}/JRE
4
Classpath =. :$ {java_home}/lib: $ {jre_home}/lib"
3. Reload bashrc
1
<Span style = "font-size: 12px;"> source ~ /. Bashrc </span>
If you are not using the root account or you do not have the permission to modify the above file, you can use the following method:
1. Execute the following command
Www.2cto.com
1
Vim ~ /. Bashrc
Note: If the execution is complete: Vim ~ /. Bashrc outputs the following information:
1
The program "Vim" is included in the following software packages:
2
* Vim
3
* Vim-gnome
4
* Vim-tiny
5
* Vim-GTK
6
* Vim-NOx
7
Please try: sudo apt-Get install <selected software package>
This indicates that you have not installed Vim. Please execute:
1
Sudo apt-Get install Vim
Press Y to press Enter. Wait until the installation is complete.
2. Open the bashrc file and add the following entries to it.
Www.2cto.com
1
Export java_home =/opt/Java/jdk1.7.0 _ 07
2
Export jre_home =$ {java_home}/JRE
3
Export classpath =. :$ {java_home}/lib :$ {jre_home}/lib
4
Export path =$ {java_home}/bin: $ path
Note: Please note that you do not need to enter it urgently after running. You must press the letter I to enter the editing mode before moving the cursor input.
After entering the preceding content, Press ESC to exit the editing mode, move the cursor to the end, and enter ': WQ! 'To save and exit.
3. Save and execute the following command to make it take effect immediately
1
Source ~ /. Bashrc
4. Configure the default JDK version
Ubuntu may have a default JDK, such as openjdk. To set the installed JDK to the default JDK version, perform the following Configuration:
Www.2cto.com
1
Sudo Update-alternatives -- install/usr/bin/Java/opt/Java/jdk1.7.0 _ 07/bin/Java 300
2
Sudo Update-alternatives -- install/usr/bin/javac/opt/Java/jdk1.7.0 _ 07/bin/javac 300
3
Sudo Update-alternatives -- install/usr/bin/Jar/opt/Java/jdk1.7.0 _ 07/bin/jar 300
4
Sudo Update-alternatives -- install/usr/bin/javah/opt/Java/jdk1.7.0 _ 07/bin/javah 300
5
Sudo Update-alternatives -- install/usr/bin/javap/opt/Java/jdk1.7.0 _ 07/bin/javap 300
Then execute:
Www.2cto.com
1
Sudo Update-alternatives -- config Java
JDK versions are listed as follows:
Three candidate items can be used to replace Java (/usr/bin/Java ).
1
Select the path priority status
2
------------------------------------------------------------
3
* 0/usr/lib/JVM/java-6-openjdk/JRE/bin/Java 1061 automatic mode
4
1/usr/lib/JVM/java-6-openjdk/JRE/bin/Java 1061 manual mode
5
2/usr/lib/JVM/Java-6-sun/JRE/bin/Java 63 manual mode
6
3/opt/Java/jdk1.7.0 _ 07/bin/Java 300 manual mode
To maintain the current value [*], press the Enter key or enter the selected number: 3
Update-Alternatives:/opt/Java/jdk1.7.0 _ 07/bin/Java is used to provide/usr/bin/Java (Java) in manual mode.
Note: if there is not the above prompt, but there is only one candidate item in the Link Group Java:/opt/Java/jdk1.7.0 _ 07/bin/Java without configuration. This is also normal, so ignore it.
Www.2cto.com
Check JDK
1
Java-version
1
@-Virtualbox :~ $ Java-version
2
Java version "1.7.0 _ 07"
3
Java (TM) se Runtime Environment (build 1.7.0 _ 07-b10)
4
Java hotspot (TM) Client VM (build 23.3-b01, mixed mode)