ubuntu环境下JDK8的 安装与配置

时间:2022-06-22 15:24:53

1、下载JDK8安装包

         下载地址是官网:http://www.Oracle.com/technetwork/Java/javase/downloads/jdk8-downloads-2133151.html

2、解压

              使用终端命令在/usr/local目录下新建java文件夹,命令行:sudo mkdir /usr/local/java

              将下载到压缩包拷贝到java文件夹中,命令行:   cp jdk-8u25-linux-x64.tar.gz /usr/local/java

             进入java目录,命令行:cd /usr/local/java

             解压压缩包,命令行: sudo tar xvf jdk-8u25-linux-x64.tar.gz

              然后把压缩包删除,命令行:sudo rm jdk-8u25-linux-x64.tar.gz

3、设置jdk环境变量

              这里采用全局设置方法,它是是所有用户的共用的环境变量

              输入:$sudo gedit ~/.bashrc,在文件末尾添加:

             export JAVA_HOME=/usr/local/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

4.,输入命令使之生效:source ~/.bashrc

4、更新默认JDK

# sudo update-alternatives --install /usr/bin/java java /usr/local/java/jdk1.8.0_121/bin/java 300

# sudo update-alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.8.0_121/bin/javac 300

# sudo update-alternatives --config java

5.测试结果

# java –version