CentOS 7安装Java
2021/11/11 7:10:16
本文主要是介绍CentOS 7安装Java,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
本文介绍在Vagrant搭建的CentOS安装OpenJDK。
1. 启动虚拟机
D:\sandbox\code\demo>vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Resuming suspended VM... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key ==> default: Machine booted and ready! ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: flag to force provisioning. Provisioners marked to run always will still run.
2. ssh登录虚拟机
D:\sandbox\code\demo>vagrant ssh Last login: Tue Nov 9 14:15:16 2021 from 10.0.2.2 Last login: Tue Nov 9 14:15:16 2021 from 10.0.2.2 [vagrant@localhost ~]$
3. 安装OpenJDK 11
[vagrant@localhost ~]$ sudo yum install java-11-openjdk-devel
4. 确认Java安装成功
[vagrant@localhost ~]$ java -version openjdk version "11.0.13" 2021-10-19 LTS OpenJDK Runtime Environment 18.9 (build 11.0.13+8-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8-LTS, mixed mode, sharing)
5. 安装OpenJDK 8
[vagrant@localhost ~]$ sudo yum install java-1.8.0-openjdk-devel
6. 虽然安装了两个版本的JDK,但是默认JDK是11
[vagrant@localhost ~]$ java -version openjdk version "11.0.13" 2021-10-19 LTS OpenJDK Runtime Environment 18.9 (build 11.0.13+8-LTS) OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8-LTS, mixed mode, sharing)
7. 如果要切换默认JDK的版本,可以
[vagrant@localhost ~]$ sudo alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- + 1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-1.el7_9.x86_64/bin/java) * 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64/jre/bin/java) Enter to keep the current selection[+], or type selection number:
8. 如果要卸载JDK
sudo yum remove java-1.8.0-openjdk-devel
参考
How to Install Java on CentOS 7
这篇关于CentOS 7安装Java的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-16ShardingSphere 如何完美驾驭分布式事务与 XA 协议?
- 2024-11-16ShardingSphere如何轻松驾驭Seata柔性分布式事务?
- 2024-11-16Maven资料入门指南
- 2024-11-16Maven资料入门教程
- 2024-11-16MyBatis Plus资料:新手入门教程与实践指南
- 2024-11-16MyBatis-Plus资料入门教程:快速上手指南
- 2024-11-16Mybatis资料入门教程:新手必看指南
- 2024-11-16MyBatis资料详解:新手入门与初级实战指南
- 2024-11-16MyBatisPlus资料:初学者入门指南与实用教程
- 2024-11-16MybatisPlus资料详解:初学者入门指南