2、Linux

2、Linux,第1张

2、Linux

参考博客:https://blog.csdn.net/pdsu161530247/article/details/81582980

一、下载和安装

问题1:从哪里下载
oracle官网jdk下载地址传送门

问题2:jdk-8u231-linux-x64.tar.gz这个名称有什么含义
tar是linux下的一种打包格式,gz是压缩算法。tar.gz的含义是,使用tar格式进行打包,并且用gz算法进行压缩。所以linux下也存在xxx.tar文件,这种文件就是只打包不压缩。
所以解压命令就很容易理解为什么是 tar -zxvf xxx.tar.gz了,因为tar就是打包和解包命令。

问题3:将jdk安装在/usr/local下还是/opt下?参考博客传送门
解答:先来看看/opt和 /usr

/opt Here’s where optional stuff is put. Trying out the latest Firefox beta? Install it to /opt where you can delete it without affecting other settings. Programs in here usually live inside a single folder whick contains all of their data, libraries, etc.

/opt这里主要存放那些可选的程序。你想尝试最新的firefox测试版吗?那就装到/opt目录下吧,这样,当你尝试完,想删掉firefox的时候,你就可 以直接删除它,而不影响系统其他任何设置。安装到/opt目录下的程序,它所有的数据、库文件等等都是放在同个目录下面。

/usr/local This is where most manually installed (ie. outside of your package manager) software goes. It has the same structure as /usr. It is a good idea to leave /usr to your package manager and put any custom scripts and things into /usr/local, since nothing important normally lives in /usr/local.

/usr/local这里主要存放那些手动安装的软件,即 不是通过“npm”或apt-get安装的软件。它和/usr目录具有相类似的目录结构。让apt-get软件包管理器来管理/usr目录,而把自定义的脚本(scripts)放到/usr/local目录下面,我想这应该是个不错的主意。

从上面可以知道,/opt目录下的文件就算整个文件夹删掉,也不会影响系统的其他任何设置。很明显jdk并不能删掉,否则可能会影响到其他java程序的运行。并且jdk是我们手动安装的软件,所以应该放在/usr/local下。

二、配置环境变量

Linux环境变量文件在/etc/profile,所以我们编辑profile文件

vim /etc/profile
# 添加环境变量
export JAVA_HOME=/usr/local/jdk1.8.0_181  #jdk安装目录
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}

# 通过命令source /etc/profile让profile文件立即生效
source /etc/profile
#测试
java -version

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5610613.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存