linux安装jdk详细步骤
Linux安装JDK详细教程(图文教程)
这里介绍两种方式:yum安装方式和手动安装
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001025962-530687434.png)
1.2 安装JDK1.8
输入命令:yum install -y java-1.8.0-openjdk.x86_64
没权限执行这行:sudo yum install -y java-1.8.0-openjdk.x86_64
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001026270-1722579851.png)
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001025671-682132360.png)
出现Complete!安装完成。
1.3 查看JDK版本
输入命令:java -version
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001024955-2005732135.png)
默认安装到usr/lib/jvm目录下
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001024976-432924183.png)
2、手动安装
2.1 卸载OpenJDK以及相关的Java文件
查看Java信息及相关的Java文件
查看JDK信息,输入命令:java -version 检测JDK安装包,输入命令:rpm -qa | grep java
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001025082-38914450.png)
删除Java相关文件(/usr/lib/jvm是默认openjdk安装路径)
进入安装目录,输入命令:cd /usr/lib/jvm
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001024953-1344957223.png)
删除Java相关文件(注意:会删除所有文件,如有其他文件,请不要使用此命令删除),输入命令:rm -rf /usr/lib/jvm
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001024808-186811624.png)
2.2 安装JDK
- 新建一个存放安装包的文件夹创建文件夹,输入命令:mkdir /usr/local/java
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001025016-1643934073.png)
- 将下载的安装包传到该文件夹
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001025361-908514269.png)
- 解压安装包,输入命令:
tar -zxvf jdk-8u351-linux-x64.tar.gz
- 修改配置文件/etc/profile,配置环境变量,输入命令:
vim /etc/profile
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001025316-610617941.png)
在配置文件最下方添加下面三种任意一种:
注意:JAVA_HOME=/devFile/jdk/jdk1.8.0_261 就是你自己的目录 #java environment export JAVA_HOME=/usr/local/java/jdk1.8.0_261 export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar export PATH=$PATH:${JAVA_HOME}/bin #java environment export JAVA_HOME=/home/jdk/jdk1.8.0_261 export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/ export PATH=$PATH:$JAVA_HOME/bin #java environment export JAVA_HOME=/usr/local/java/jdk1.8.0_261 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001025402-1007999512.png)
- 重新加载配置
输入命令:source /etc/profile
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001024621-757003589.png)
- 查看安装情况
输入命令:java -version
![0](https://img2024.cnblogs.com/blog/1374811/202404/1374811-20240410001024965-1752832677.png)
JDK就安装好啦!
更多技术请关注微信公众号:程序员技术前沿