Install and configure JDK7 under Linux

1. Download JDK

The latest JDK version is: Java SE Development Kit 7u5

Download address: http://download.oracle.com/otn-pub/java/jdk/7u5-b06/jdk-7u5-linux-i586.tar.gz

Check out the latest: http://www.oracle.com/technetwork/java/javase/downloads/index.html

2. Unzip the installation

We install the JDK to this path: /usr/lib/jvm
If there is no such directory (of course not the first time), we will create a new directory

1
2
cd  / usr / lib
sudo   mkdir   jvm

After the establishment is complete, we go to the directory of the compressed package we just downloaded, unzip it into the folder we just created, and modify the name to facilitate our management.

1
2
3
sudo  tar  zxvf  . / jdk - 7 - linux - i586 .tar .gz   - C  / usr / lib / jvm
cd  / usr / lib / jvm
sudo   mv   jdk1 . 7.0_05 /   jdk7

 3. Configure environment variables

1 gedit ~/.bashrc

add at the end of the opened file

1
2
3
4
export  JAVA_HOME = / usr / lib / jvm / jdk7
export  JRE_HOME = $ { JAVA_HOME } / jre
export  CLASSPATH = . : $ { JAVA_HOME } / lib : $ { JRE_HOME } / lib
export  PATH = $ { JAVA_HOME } / bin : $ PATH

Save and exit, then enter the following command to make it take effect

1 source ~/.bashrc

 4. Configure the default JDK (in general, this step can be omitted)

Because some Linux distributions already have a default JDK, such as OpenJDK, etc. So in order to make the JDK version we just installed become the default JDK version, we also need to perform the following configuration.
Execute the following command:

1
2
sudo  update - alternatives  -- install  / usr / bin / java  java  / usr / lib / jvm / jdk7 / bin / java  300
sudo  update - alternatives  -- install  / usr / bin / javac  javac  / usr / lib / jvm / jdk7 / bin / javac  300

 Note: If the above two commands cannot find the path, just restart the computer and repeat the above two lines of code and it will be OK.

Execute the following code to see the current various JDK versions and configurations:

1 sudo update-alternatives --config java

 5. Test

Open a terminal and enter the following command:

1 java -version

Show results:

1
2
3
java  version  "1.7.0_05"
Java ( TM )   SE   Runtime   Environment   ( build   1.7.0_05 - b05 )
Java  HotSpot ( TM )  Server  VM  ( build  23.1 - b03 ,  mixed  mode )

This means that the java command is ready to run.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326461472&siteId=291194637