- 官网下载JDK,附官网网址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html。选择相应的 .gz包下载 。
- 切换到root用户权限。
解压缩,放到指定目录(以jdk-8u121-linux-x64.tar.gz为例)。
× 创建目录mkdir /home/xqq/software/java
× 解压缩放入目录中
tar -zxvf jdk-8u121-linux-x64.tar.gz -C /home/xqq/software/java
修改环境变量。
vim ~/.bashrc
文件末尾追加下列内容:
#set oracle jdk environment export JAVA_HOME=/home/xqq/software/java/jdk1.8.0_121 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
使环境变量马上生效:
source ~/.bashrc
设置系统默认JDK版本。
update-alternatives --install /usr/bin/java java /home/xqq/software/java/jdk1.8.0_121/bin/java 300 update-alternatives --install /usr/bin/javac javac /home/xqq/software/java/jdk1.8.0_121/bin/java 300 update-alternatives --install /usr/bin/javap javap /home/xqq/software/java/jdk1.8.0_121/bin/javap 300 update-alternatives --install /usr/bin/javah javah /home/xqq/software/java/jdk1.8.0_121/bin/javah 300 update-alternatives --install /usr/bin/jar jar /home/xqq/software/java/jdk1.8.0_121/bin/jar 300
然后执行:
update-alternatives --config java
测试JDK。
java -version 显示如下结果: java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
Ubuntu16配置JDK环境
最新推荐文章于 2024-08-22 23:07:39 发布