Home > Operation and Maintenance > CentOS > How to install jdk in centos system

How to install jdk in centos system

王林
Release: 2020-03-23 14:25:03
Original
2068 people have browsed it

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
Copy after login

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
Copy after login

(Recommended tutorial: centos usage tutorial)

Then enter the java directory, command Line:

cd /usr/local/java
Copy after login

Decompress the compressed package, command line:

sudo tar xvf jdk-7u45-linux-x64.tar.gz
Copy after login

Then you can delete the compressed package, command line:

sudo rm jdk-7u45-linux-x64.tar.gz
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

Make the profile effective

4. Verify whether the installation is successful

In the terminal

java -version
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template