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

Jun 24, 2024 am 06:32 AM

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How To List Or Check All Installed Linux Kernels From Commandline How To List Or Check All Installed Linux Kernels From Commandline Mar 23, 2025 am 10:43 AM

Linux Kernel is the core component of a GNU/Linux operating system. Developed by Linus Torvalds in 1991, it is a free, open-source, monolithic, modular, and multitasking Unix-like kernel. In Linux, it is possible to install multiple kernels on a sing

What is the Linux best used for? What is the Linux best used for? Apr 03, 2025 am 12:11 AM

Linux is best used as server management, embedded systems and desktop environments. 1) In server management, Linux is used to host websites, databases, and applications, providing stability and reliability. 2) In embedded systems, Linux is widely used in smart home and automotive electronic systems because of its flexibility and stability. 3) In the desktop environment, Linux provides rich applications and efficient performance.

Linux Kernel 6.14 RC6 Released Linux Kernel 6.14 RC6 Released Mar 24, 2025 am 10:21 AM

Linus Torvalds has released Linux Kernel 6.14 Release Candidate 6 (RC6), reporting no significant issues and keeping the release on track. The most notable change in this update addresses an AMD microcode signing issue, while the rest of the updates

What are the 5 basic components of Linux? What are the 5 basic components of Linux? Apr 06, 2025 am 12:05 AM

The five basic components of Linux are: 1. The kernel, managing hardware resources; 2. The system library, providing functions and services; 3. Shell, the interface for users to interact with the system; 4. The file system, storing and organizing data; 5. Applications, using system resources to implement functions.

LocalSend - The Open-Source Airdrop Alternative For Secure File Sharing LocalSend - The Open-Source Airdrop Alternative For Secure File Sharing Mar 24, 2025 am 09:20 AM

If you're familiar with AirDrop, you know it's a popular feature developed by Apple Inc. that enables seamless file transfer between supported Macintosh computers and iOS devices using Wi-Fi and Bluetooth. However, if you're using Linux and missing o

How To Monitor Battery Level And Get Notifications On Linux Using battmon How To Monitor Battery Level And Get Notifications On Linux Using battmon Mar 24, 2025 am 10:23 AM

Keeping your Laptop battery in check is very important for maintaining its longevity and ensuring you're never caught off guard by a sudden shutdown. If you’re a Linux user, you can easily monitor your Laptop's battery level and receive notifications

What is the most use of Linux? What is the most use of Linux? Apr 09, 2025 am 12:02 AM

Linux is widely used in servers, embedded systems and desktop environments. 1) In the server field, Linux has become an ideal choice for hosting websites, databases and applications due to its stability and security. 2) In embedded systems, Linux is popular for its high customization and efficiency. 3) In the desktop environment, Linux provides a variety of desktop environments to meet the needs of different users.

What is basic Linux administration? What is basic Linux administration? Apr 02, 2025 pm 02:09 PM

Linux system management ensures the system stability, efficiency and security through configuration, monitoring and maintenance. 1. Master shell commands such as top and systemctl. 2. Use apt or yum to manage the software package. 3. Write automated scripts to improve efficiency. 4. Common debugging errors such as permission problems. 5. Optimize performance through monitoring tools.

See all articles