ubuntu配置java环境-包安装文件无需下载
jdk文件下载
链接:https://pan.baidu.com/s/1GiNrIiVhIJzfTEIXtcEYuw
提取码:j6ad
复制这段内容后打开百度网盘手机App,操作更方便哦
服务器新建jvm文件夹
把下载的压缩包放上传这里面进行解压 : tar -zxvf jdk-11.0.8_linux-x64_bin.tar.gz
设置系统默认jdk版本
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.8/bin/java 300 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11.0.8/bin/javac 300 sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk-11.0.8/bin/jar 300 sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk-11.0.8/bin/javah 300 sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk-11.0.8/bin/javap 300
然后执行
sudo update-alternatives --config java
若是初次安装jdk,会有下面的提示
There is only one alternative in link group java (providing /usr/bin/java):
/usr/lib/jvm/jdk1.7.0_60/bin/java
否者,选择合适的jdk
修改环境变量
sudo vim ~/.bashrc
在末尾追加以下内容
#set oracle jdk environment export JAVA_HOME=/usr/lib/jvm/jdk-11.0.8 ## 这里要注意目录要换成自己解压的jdk 目录 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
使环境变量马上生效
source ~/.bashrc
查看是否安装
java -version