**
一、安装
**
1、在user目录下新建java文件夹:
# cd /usr/
# mkdir java
# cd java
2.下载jdk1.8,进入http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html,复制下载目录
下载JDK 8u121之前等历史版本
https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html
tar -zxvf jdk-8u251-linux-x64.tar.gz
配置环境变量
vi /etc/profile
添加如下内容
#java
export JAVA_HOME=/usr/java/jdk1.8.0_112
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib
source /etc/profile
**
二、出现的问题
**
我这里安装额JDK11环境变量没生效
删除原来的jdk版本
# rm -f /usr/bin/java
# rm -f /usr/bin/javac
# rm -f /etc/alternatives/java
# rm -f /etc/alternatives/javac
配置环境变量
sudo vim /etc/profile
###复制以下代码到文件结尾
JAVA_HOME=/usr/java/jdk1.8.0_181
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
通知系统java的位置
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk1.8.0_181/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk1.8.0_181/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/jdk1.8.0_181/bin/javaws" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/jdk1.8.0_181/bin/javaws" 1
设置默认JDK
sudo update-alternatives --set java /usr/java/jdk1.8.0_181/bin/java
sudo update-alternatives --set javac /usr/java/jdk1.8.0_181/bin/javac
sudo update-alternatives --set javaws /usr/java/jdk1.8.0_181/bin/javaws
重新载入profile
source /etc/profile
粘贴别人一篇文章,防止忘记
linux中查找jdk
直接echo $JAVA_HOME是不可以的, 使用echo $JAVA_HOME的前提条件是设置了JAVA_HOME, 如果没设置, 就什么也查不到:
ubuntu@VM-0-15-ubuntu:~/taoge$ echo $JAVA_HOME
ubuntu@VM-0-15-ubuntu:~/taoge$
那怎么查呢? 先确保安装了jdk, 如下:
ubuntu@VM-0-15-ubuntu:~/taoge$ java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
ubuntu@VM-0-15-ubuntu:~/taoge$
查java命令位置:
ubuntu@VM-0-15-ubuntu:~/taoge$ which java
/usr/bin/java
ubuntu@VM-0-15-ubuntu:~/taoge$
查软链:
ubuntu@VM-0-15-ubuntu:~/taoge$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 Jan 23 10:36 /usr/bin/java -> /etc/alternatives/java
ubuntu@VM-0-15-ubuntu:~/taoge$
查jdk目录:
ubuntu@VM-0-15-ubuntu:~/taoge$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 46 Jan 23 10:36 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
ubuntu@VM-0-15-ubuntu:~/taoge$
jdk目录是 /usr/lib/jvm/java-8-openjdk-amd64
不过, 我后来发现了一个更为简单的办法, 如下(根目录下):
ubuntu@VM-0-15-ubuntu:/$ find -name libjvm.so 2>/dev/null
./usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so
---------------------
作者:stpeace
来源:CSDN
原文:https://blog.csdn.net/stpeace/article/details/79411223
版权声明:本文为博主原创文章,转载请附上博文链接!