Home > System Tutorial > LINUX > Linux installation OpenJDK tutorial: from checking the system's own version to deleting to downloading and installing

Linux installation OpenJDK tutorial: from checking the system's own version to deleting to downloading and installing

WBOY
Release: 2024-06-24 06:32:26
Original
662 people have browsed it

Linux 安装 OpenJDK 教程:从查看系统自带版本到删除再到下载安装

Table of Contents

1. Install OpenJDK1 on Linux and check whether the system has its own version

Because some Linux systems come with OpenJDK,

We can first check whether it comes with a Chinese Linux operating system and execute the following command.

java -version
Copy after login

If there is one, but the version meets the usage conditions, then there is no need to install it

However, the version is not the Linux system log we need, so it needs to be deleted

2. Delete OpenJDK

# 1、检测jdk的安装包
rpm -qa | grep java 
# 2、将包一个个删除掉
rpm -e --nodeps +包名
# 3、检查是否删除完即可
rpm -qa | grep java
Copy after login

3. Download OpenJDK locally

Fudan University open source mirror site:

Find the version you need, download it locally, and use the remote transmission tool to upload it to the server

It is recommended to transfer it to /usr/local/java/. We will configure the environment variables easily in a moment

解压系统内核文件_解压系统找不到指定的文件_linux系统解压deb

Windows recommends the .msi installation package Linux system decompression deb, just download and install it directly, it will manually configure the environment variables.

Linux choose .tar.gz packageLinux system decompression deb, the following tutorial will teach you how to configure environment variables

解压系统内核文件_linux系统解压deb_解压系统找不到指定的文件

4. It cannot be downloaded locally, you can also use the command to download (method 1)

# 1、安装wget
yum install -y wget 
# 2、创建安装目录
mkdir /usr/local/java/
# 3、下载JDK安装包,将地址替换成你要安装的版本的下载地址,或者你从自己电脑上传到服务器也行。
wget https://mirrors.tuna.tsinghua.edu.cn/AdoptOpenJDK/16/jdk/x64/linux/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz
# 解压当前目录下的JDK压缩文件到安装目录,将下面压缩包名字替换成你下载的
tar -zxvf OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz -C /usr/local/java/
# 进入/usr/local/java/目录
cd /usr/local/java/
# 列出目录内的文件夹,看看刚刚解压出来的JDK目录名称是什么,我这里是 jdk-16.0.2+7
ls
# 设置环境变量(安装 nano 输入 apt -y install nano),如果是Centos/Redhat系统就将apt替换为yum
nano /etc/profile
# 在末尾添加对应变量,记得将下面的jdk-16.0.2+7改成你上面查到的你JDK文件夹名
# 通过方向键移动光标到末尾
# 输入下面这几串内容后,按Ctrl+O来保存,然后按一下回车确定,接着按Ctrl+X退出。
export JAVA_HOME=/usr/local/java/jdk-16.0.2+7
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
# 应用修改后的环境变量
source /etc/profile
# 软链接程序到环境变量中,记得将下面的jdk-16.0.2+7改成你上面查到的你JDK文件夹名
ln -sf /usr/local/java/jdk-16.0.2+7/bin/java /usr/bin/java
# 测试是否安装正常,显示 java version "1.8.0_261" 则为正常
java -version
Copy after login

解压系统找不到指定的文件_linux系统解压deb_解压系统内核文件

4. It cannot be downloaded locally, but you can also use commands to download (Tip 2)

# 下载wget
yum install -y wget
# 下载vim
yum install -y vim
Copy after login

# 查看可安装的openjdk包
yum list java* | grep java-1.8.0-openjdk
Copy after login

You can check the version you need and then find the x86_64 version

解压系统内核文件_解压系统找不到指定的文件_linux系统解压deb

# 下载自己需要的openJDK版本
yum install java-1.8.0-openjdk.x86_64
Copy after login

# 下载完成后,查看版本,是否对应
java -version
Copy after login

5. Expand

Ubuntu or Debian system:

下载对应版本deb包

方式1:先下载到自己笔记本上,再通过sftp上传到你的Linux服务器上

方式2:直接用wget命令下载

JDK17的x64的deb包下载地址:​​​​​​7.0.1.0.0%2B12-1_amd64.deb

Centos或Redhat系统:

若果是则将下边的dpkg命令替换为rpm,安装包也要换成rpm的。

注意:假如是非root用户登录的,自己在每条命令前加上sudo。

# 通过wget下载安装包,若报错运行一下sudo apt install wget
wget https://mirrors.tuna.tsinghua.edu.cn/Adoptium/deb/pool/main/t/temurin-17/temurin-17-jdk_17.0.1.0.0%2B12-1_amd64.deb
# 安装JDK,如果报错,可能是依赖问题,运行这条命令修改依赖:sudo apt-get -f -y install
dpkg -i temurin-17-jdk_17.0.1.0.0+12-1_amd64.deb
# 验证java安装成功没
java -version
Copy after login

三、Linux安装JDK1、查看系统是否有自带的版本,并删掉

linux系统解压deb_解压系统找不到指定的文件_解压系统内核文件

这儿就不赘言了,请回看1.1节

2、去官网下载对应的安装包,之后上传到服务器

官网地址:

linux系统解压deb_解压系统内核文件_解压系统找不到指定的文件

3、将我们下载好的JDK安装包上传到服务器,进行解压

cd /usr/java
tar -zxvf jdk-8u131-linux-x64.tar.gz
Copy after login

4、修改环境变量

# 1、用vim编辑器来编辑profile文件(按“i”进入编辑)
vim /etc/profile
# 2、在文件末尾添加以下内容
export JAVA_HOME=/usr/java/jdk1.8.0_131
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
Copy after login

5、应用更改后的环境变量

source /etc/profile
Copy after login

6、软链接程序到环境变量中

# 记得将下面的jdk1.8.0_131改成你上面查到的你JDK文件夹名 
ln -sf /usr/local/java/jdk-16.0.2+7/bin/java /usr/bin/java
Copy after login

7、测试是否安装正常

 java version 
Copy after login

若果是:"1.8.0_261",则为正常java-version

四、其他版本(Windows、MacOS)安装1、MacOS安装JDK

苹果M1安装JDK环境-青山小站|一个在帝都搬砖的新时代农户工

2、Windows安装JDK2.1、使用IDEA的集成JDK

打开IDEA,点击:ProjectStructure

解压系统内核文件_解压系统找不到指定的文件_linux系统解压deb

下载版本

版本下载的路径可以手动更改(路径上最好不要有英文字符)

解压系统内核文件_linux系统解压deb_解压系统找不到指定的文件

2.2、去官网下载JDK

首先下载你要装的JDK版本的Windows版ZIP包

下边以JDK17为例,下载地址:

下载然后解压,解压后的路径最好不要用英文字符

linux系统解压deb_解压系统内核文件_解压系统找不到指定的文件

编辑环境变量

解压系统内核文件_linux系统解压deb_解压系统找不到指定的文件

新建→变量名输入JAVA_HOME→变量值输入你后边复制的JDK目录

解压系统内核文件_解压系统找不到指定的文件_linux系统解压deb

打开Path→新建→输入→确定

# 输入内容
%JAVA_HOME%bin
Copy after login

解压系统找不到指定的文件_解压系统内核文件_linux系统解压deb

打开cmd,查看Java版本(是否安装成功)

# 输入命令 
java -version
Copy after login

解压系统内核文件_linux系统解压deb_解压系统找不到指定的文件

The above is the detailed content of Linux installation OpenJDK tutorial: from checking the system's own version to deleting to downloading and installing. For more information, please follow other related articles on the PHP Chinese website!

source:itcool.net
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