一、解压安装包下载
现在oracle上下载安装包
1、新建目录,然后使用ftp工具保存上传。
mkdir /usr/java
2、解压
tar -zxvf jdk-8u261-linux-x64.tar.gz
3、配置环境变量
修改/etc/profile文件
vim /etc/profile
在文件末尾添加jdk信息,JAVA_HOME信息根据自己的jdk包自定义,其他不变
export JAVA_HOME=/usr/java/jdk1.8.0_261 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin export PATH=$PATH:${JAVA_PATH}
结果如图:
4、使配置文件生效
source /etc/profile
5、验证jdk是否安装成功
java -version
结果如图:
二、yum方式安装
1、检查是否已安装
rpm -qa |grep java
已安装删除:
rpm -qa | grep java | xargs rpm -e --nodeps
2、查找
yum search java|grep jdk
[root@VM_0_11_centos jvm]# yum search java|grep jdk ldapjdk-javadoc.i686 : Javadoc for ldapjdk java-1.6.0-openjdk.i686 : OpenJDK Runtime Environment java-1.6.0-openjdk-demo.i686 : OpenJDK Demos java-1.6.0-openjdk-devel.i686 : OpenJDK Development Environment java-1.6.0-openjdk-javadoc.i686 : OpenJDK API Documentation java-1.6.0-openjdk-src.i686 : OpenJDK Source Bundle java-1.7.0-openjdk.i686 : OpenJDK Runtime Environment java-1.7.0-openjdk-demo.i686 : OpenJDK Demos java-1.7.0-openjdk-devel.i686 : OpenJDK Development Environment java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation java-1.7.0-openjdk-src.i686 : OpenJDK Source Bundle java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment java-1.8.0-openjdk-debug.i686 : OpenJDK Runtime Environment with full debug on java-1.8.0-openjdk-demo.i686 : OpenJDK Demos java-1.8.0-openjdk-demo-debug.i686 : OpenJDK Demos with full debug on java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment java-1.8.0-openjdk-devel-debug.i686 : OpenJDK Development Environment with full java-1.8.0-openjdk-headless.i686 : OpenJDK Runtime Environment java-1.8.0-openjdk-headless-debug.i686 : OpenJDK Runtime Environment with full java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK API Documentation for packages java-1.8.0-openjdk-src.i686 : OpenJDK Source Bundle java-1.8.0-openjdk-src-debug.i686 : OpenJDK Source Bundle for packages with ldapjdk.i686 : The Mozilla LDAP Java SDK
3、安装
yum install java-1.8.0-openjdk -y 或 yum install java-1.8.0-openjdk* -y
*会多安装一些文件,如debug,不加* 不影响。
-y 用来跳过安装确认
安装完成的目录在/usr/lib/jvm下
[root@VM_0_11_centos jvm]# ls /usr/lib/jvm java-1.8.0-openjdk-1.8.0.265.b01-0.el6_10.i386 jre jre-1.8.0 jre-1.8.0-openjdk-1.8.0.265.b01-0.el6_10.i386 jre-1.8.0-openjdk.i386 jre-openjdk
只有java-1.8.0-openjdk-1.8.0.265.b01-0.el6_10.i386是唯一的目录,其他的都是软链接。这个就是jdk的安装目录,环境变量要指向这里。
4、配置环境变量并使之生效。