Home  >  Article  >  php教程  >  Install JDK and configure environment variables on Linux

Install JDK and configure environment variables on Linux

高洛峰
高洛峰Original
2016-12-17 13:39:181309browse

JDK download address:

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Install JDK and configure environment variables on Linux

Choose 64-bit or 32-bit download according to the version of Linux system , the official now provides rpm and tar.gz versions for download.


Installation:

[root@oracle cdrom]# rpm -ivh jdk-8u25-linux-x64.rpm


Configure jdk environment variables

Method 1: Set variables under Shell (this method Only valid for the current shell, if you open another shell, you need to reconfigure it)

export JAVA_HOME=/usr/java/jdk1.7.0_40/
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$ JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

(It is also OK if you only configure export PATH=/usr/java/jdk1.7.0_40/bin:$PATH)

Method 2: Modify the /etc/profile file (this method is once and for all, set once and is valid for all users)

Open the /etc/profile file with the vim editor and add the definition of environment variables at the end of the file

JAVA_HOME=/usr/java/jdk1 .8.0_25/

PATH=$JAVA_HOME/bin:$PATH

CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH

Save Exit and check the java version

[root@oracle cdrom]# java -version

java version "1.8.0_25"

Java(TM) SE Runtime Environment (build 1.8.0_25-b17)

Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

means the installation is successful

Method 3: Modify the ~/.bashrc file (this method is only effective for the current user after modification, and all shells of this user will be affected) Valid)

Open the ~/.bashrc file with the vim editor

Add the definition of the jdk environment variable at the end of the file

set JAVA_HOME=/usr/java/jdk1.8.0_25/

export JAVA_HOME

set PATH=$ JAVA_HOME/bin:$PATH

export PATH

set CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export CLASSPATH



More Linux installations For articles related to JDK and configuring environment variables, please pay attention to the PHP Chinese website!

Statement:
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