参考
0. 准备阶段
- https://www.yuque.com/tanning/epv4c9/aw7wci#zsNCQ
- 准备一个jdk,此为离线安装
1. 建立sh脚本文件
vim java.sh
#!/bin/bash
javaPath=/usr/local/
tempPath=/tmp/testFilePath/
read -p "请输入下载的jdk名字(全名):" jdkName
echo "你输入的数是:$jdkName"
mkdir $tempPath
cp $jdkName $tempPath
cd $tempPath
tar -zxvf $jdkName
dirName="java"
rm -rf $jdkName
tempName=`ls`
mv $tempName "java"
fileName=`ls`
mv $fileName $javaPath
cd ~
rm -rf $tempPath
echo "export JAVA_HOME=$javaPath$dirName">>/etc/profile
echo "export CLASSPATH=.:\$JAVA_HOME/jre/lib/rt.jar:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar">>/etc/profile
echo "export PATH=\$JAVA_HOME/bin:\$PATH">>/etc/profile
#重新加载profile文件
source /etc/profile
2. 运行 sh
一句命令:
**chmod -R 777 java.sh && source java.sh**
2.1 给与java.sh文件和tmp文件夹读写权限
chmod -R 777 java.sh
chmod -R 777 /tmp
-R 是指级联应用到目录里的所有子目录和文件
777 是所有用户都拥有最高权限
2.2 运行 java.sh
- 把脚本和下载的jdk放在同一个目录中
./java.sh
or
source java.sh
2.3 如果配置没有生效手动使配置生效
source /etc/profile
3. 环境说明
- linux ```shell LSB Version: :core-4.1-amd64:core-4.1-noarch Distributor ID: CentOS Description: CentOS Linux release 8.2.2004 (Core) Release: 8.2.2004 Codename: Core
[jdk-8u281-linux-x64.tar.zip](https://www.yuque.com/attachments/yuque/0/2021/zip/1642320/1628238530718-a80d7f7f-07ac-4321-b3de-e5828455862e.zip?_lake_card=%7B%22src%22%3A%22https%3A%2F%2Fwww.yuque.com%2Fattachments%2Fyuque%2F0%2F2021%2Fzip%2F1642320%2F1628238530718-a80d7f7f-07ac-4321-b3de-e5828455862e.zip%22%2C%22name%22%3A%22jdk-8u281-linux-x64.tar.zip%22%2C%22size%22%3A143047365%2C%22type%22%3A%22%22%2C%22ext%22%3A%22zip%22%2C%22source%22%3A%22transfer%22%2C%22status%22%3A%22done%22%2C%22mode%22%3A%22title%22%2C%22download%22%3Atrue%2C%22id%22%3A%22AU7Y7%22%2C%22card%22%3A%22file%22%7D)
<a name="KOtgw"></a>
# [shell 问题总汇](https://www.yuque.com/tanning/epv4c9/vqsvn8?view=doc_embed)
<a name="TyZhH"></a>
# 备注
<a name="o3pzs"></a>
## 单步走
```shell
# 解压
tar -zxvf jdk-8u351-linux-x64.tar.gz
# 重命名解压文件
mv jdk1.8.0_351 java
# 移动到 usr/local下
sudo mv java /usr/local/java
# 编辑环境
sudo vim /etc/profile
export JAVA_HOME=/usr/local/java
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
# 让环境生效
source /etc/profile
# 测试
java -version
jps
# 把root 用户加入 vmware 组 (我使用vmware用户处理的所以root用户想使用的加入
usermod -G vmware root