Home >Operation and Maintenance >CentOS >How to install jdk in centos system
1. Source code package preparation:
First download jdk from the official website, http://www.oracle.com/technetwork /java/javase/downloads/jdk7-downloads-1880260.html, download jdk-7u45-linux-x64.tar.gz here, download to the main directory
2, decompress the source code package
Create a new java folder in the /usr/local directory through the terminal, command line:
sudo mkdir /usr/local/java
Then copy the downloaded compressed package to the java folder, command Line:
Enter the directory where the jdk source package is located
cp jdk-7u45-linux-x64.tar.gz /usr/local/java
(Recommended tutorial: centos usage tutorial)
Then enter the java directory, command Line:
cd /usr/local/java
Decompress the compressed package, command line:
sudo tar xvf jdk-7u45-linux-x64.tar.gz
Then you can delete the compressed package, command line:
sudo rm jdk-7u45-linux-x64.tar.gz
3. Set jdk environment variables
The global setting method is used here, which is to modify etc/profile, which is an environment variable shared by all users
sudo gedit /etc/profile
Open Then add
export JAVA_HOME=/usr/local/java/jdk1.7.0_45 export JRE_HOME=/usr/local/java/jdk1.7.0_45/jre export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin: $PATH
at the end. Please remember that during the above addition process, do not add spaces on both sides of the equal sign, otherwise "not a valid identifier" will appear, because when source /etc/profile Extra spaces will not be recognized and will be understood as part of the path.
Then save
source /etc/profile
Make the profile effective
4. Verify whether the installation is successful
In the terminal
java -version
Check if the installation is successful.
If successful, it will be displayed as follows:
java version "1.7.0_45" Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
Recommended related video tutorials: linux video tutorial
The above is the detailed content of How to install jdk in centos system. For more information, please follow other related articles on the PHP Chinese website!