当前位置:首页 > ubuntu相关 > 正文内容

Ubuntu 使用apt命令安装 JDK

我们编译一个java文件里发现提示没有安装java编译器

Command 'javac' not found, but can be installed with:
sudo apt install openjdk-11-jdk-headless # version 11.0.11+9-0ubuntu2~20.04, or
sudo apt install default-jdk # version 2:1.11-72
sudo apt install openjdk-13-jdk-headless # version 13.0.7+5-0ubuntu1~20.04
sudo apt install openjdk-16-jdk-headless # version 16.0.1+9-1~20.04
sudo apt install openjdk-17-jdk-headless # version 17+35-1~20.04
sudo apt install openjdk-8-jdk-headless # version 8u292-b10-0ubuntu1~20.04
sudo apt install ecj # version 3.16.0-1


打开终端输入:

apt-cache search openjdk


查看下资源库中JDK的相应版本

default-jdk-headless - Standard Java or Java compatible Development Kit (headless)
default-jre - 标准 Java 或兼容 Java 的运行环境
default-jre-headless - 标准 Java 或兼容 Java 的运行环境(headless)
openjdk-11-jre - OpenJDK Java 运行时环境,使用 Hotspot JIT
default-jdk - Standard Java or Java compatible Development Kit
default-jdk-doc - Standard Java or Java compatible Development Kit (documentation)
openjdk-11-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-11-doc - OpenJDK Development Kit (JDK) documentation
openjdk-11-jdk - OpenJDK Development Kit (JDK)
openjdk-11-jdk-headless - OpenJDK Development Kit (JDK) (headless)
openjdk-11-jre-headless - OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-11-source - OpenJDK Development Kit (JDK) source files
libreoffice - office productivity suite (metapackage)
openjdk-8-jre - OpenJDK Java 运行时环境,使用 Hotspot JIT
crypto-policies - unify the crypto policies used by different applications and libraries
jtreg - Regression Test Harness for the OpenJDK platform
libhsdis0-fcml - HotSpot disassembler plugin using FCML
libjax-maven-plugin - Using the xjc goal with OpenJDK 11+
openjdk-11-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-11-jre-dcevm - Alternative VM for OpenJDK 11 with enhanced class redefinition
openjdk-11-jre-zero - Alternative JVM for OpenJDK, using Zero
openjdk-8-dbg - Java runtime based on OpenJDK (debugging symbols)
openjdk-8-demo - Java runtime based on OpenJDK (demos and examples)
openjdk-8-doc - OpenJDK Development Kit (JDK) documentation
openjdk-8-jdk - OpenJDK Development Kit (JDK)
openjdk-8-jdk-headless - OpenJDK Development Kit (JDK) (headless)


我们安装JDK-8

sudo apt install openjdk-8-jdk

正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
将会同时安装下列软件:
ca-certificates-java fonts-dejavu-extra java-common libatk-wrapper-java
libatk-wrapper-java-jni libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev
libxcb1-dev libxdmcp-dev libxt-dev openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless
x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev
建议安装:
default-jre libice-doc libsm-doc libx11-doc libxcb-doc libxt-doc openjdk-8-demo
openjdk-8-source visualvm icedtea-8-plugin fonts-ipafont-gothic fonts-ipafont-mincho
fonts-wqy-microhei fonts-wqy-zenhei
下列【新】软件包将被安装:
ca-certificates-java fonts-dejavu-extra java-common libatk-wrapper-java
libatk-wrapper-java-jni libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libxau-dev
libxcb1-dev libxdmcp-dev libxt-dev openjdk-8-jdk openjdk-8-jdk-headless openjdk-8-jre
openjdk-8-jre-headless x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev
升级了 0 个软件包,新安装了 21 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
需要下载 43.4 MB 的归档。
解压缩后会消耗 162 MB 的额外空间。
您希望继续执行吗? [Y/n] y


可见jre等一些软件同时被安装

正在处理用于 ca-certificates (20210119~20.04.2) 的触发器 ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
done.
正在处理用于 sgml-base (1.29.1) 的触发器 ...
正在设置 x11proto-dev (2019.2-1ubuntu1) ...
正在设置 libxau-dev:amd64 (1:1.0.9-0ubuntu1) ...
正在设置 libice-dev:amd64 (2:1.0.10-0ubuntu1) ...
正在设置 libsm-dev:amd64 (2:1.2.3-1) ...
正在设置 libxdmcp-dev:amd64 (1:1.1.3-0ubuntu1) ...
正在设置 x11proto-core-dev (2019.2-1ubuntu1) ...
正在设置 libxcb1-dev:amd64 (1.14-2) ...
正在设置 libx11-dev:amd64 (2:1.6.9-2ubuntu1.2) ...
正在设置 libxt-dev:amd64 (1:1.1.5-1) ...


配置环境变量, 编辑如下文件

vim ~/.bashrc

在最后一行加:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

测试jdk是否安装成功:

java -version

openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~20.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

完成安装


扫描二维码推送至手机访问。

版权声明:本文由uuucd.cn发布,如需转载请注明出处。

本文链接:https://www.uuucd.cn/ubuntu/5.html

标签: ubuntu相关

相关文章

ubuntu新建用户后终端只显示“$”

ubuntu新建用户后终端只显示“$”

buntu新建用户后进入终端只显示“$”符号        经过原理分析可能原因是你的默认shell,如其它的ba等将登录shell 改成bash办法:编辑文件:sudo vi /etc/passwd...

Linux常用修改权限的命令

Linux常用修改权限的命令

常用修改权限的命令:sudo chmod 600 ××× (只有所有者有读和写的权限)sudo chmod 644 ××× (所有者有读和写的权限,组用户读的权限)sudo chmod 700 ××× (只有所有者有读和写以及执行的权限)s...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。