ubutun安装jdk和设置环境变量

一、下载安装包

        我试着用wget 去下载官网的文件会有问题。下载的文件为空。(以后在解决)

        我是用浏览器下载的。官网下载地址:http://download.oracle.com/otn-pub/java/jdk/8u73-b02/jdk-8u73-linux-x64.rpm

二、在下载以前看一下自己机器的操作系统位数

        getconf LONG_BIT //查看操作系统位数

        lsb_release -a // 操作系统信息

三、解压下载的文件

        我将文件解压到目录 /media/pkx/xuexi_1/jdkInstall 下

       tar -zxvf jdk-8u73-linux-x64.tar.gz  -C /media/pkx/xuexi_1/jdkInstall

    解压直到最后出现 总用量xxx

    jdk1.8.0_73/man/ja_JP.UTF-8/man1/jmap.1
    jdk1.8.0_73/man/ja_JP.UTF-8/man1/javac.1
    jdk1.8.0_73/man/ja_JP.UTF-8/man1/wsimport.1
    jdk1.8.0_73/man/ja_JP.UTF-8/man1/tnameserv.1
    jdk1.8.0_73/man/ja_JP.UTF-8/man1/pack200.1
    jdk1.8.0_73/man/ja_JP.UTF-8/man1/jcmd.1
    jdk1.8.0_73/man/ja_JP.UTF-8/man1/javapackager.1
    jdk1.8.0_73/man/ja_JP.UTF-8/man1/jstat.1
    root@pkx-Aspire-V5-452G:/media/pkx/xuexi/jdk# ll
    总用量 177072
然后切换到 安装目录下 运行javac:

root@pkx-Aspire-V5-452G:/media/pkx/xuexi_1/jdkInstall/jdk1.8.0_73/bin# javac

出现问题(我以前安装过openjdk):

程序 'java' 已包含在下列软件包中:
 * default-jre
 * gcj-4.9-jre-headless
 * gcj-5-jre-headless
 * openjdk-7-jre-headless
 * gcj-4.8-jre-headless
 * openjdk-6-jre-headless
 * openjdk-8-jre-headless
请尝试:apt-get install <选定的软件包>

解决方案:

    运行以下命令:

    root@pkx-Aspire-V5-452G:/media/pkx/xuexi_1/jdkInstall/jdk1.8.0_73/bin# sudo update-alternatives --install /usr/bin/javac javac   /media/pkx/xuexi_1/jdkInstall/jdk1.8.0_73/bin/javac 300

root@pkx-Aspire-V5-452G:/media/pkx/xuexi_1/jdkInstall/jdk1.8.0_73/bin# sudo update-alternatives --install /usr/bin/java java  /media/pkx/xuexi_1/jdkInstall/jdk1.8.0_73/bin/java 300
即可解决

环境变量的配置:

    二种放案

    第一种:sudo gedit  ~/.bashrc

       追加红色字体的代码

            
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi

export JAVA_HOME =/media/pkx/xuexi_1/jdkInstall/jdk1.8.0_73
export JRE_HOME =${JAVA_HOME}/jre
export CLASSPATH =.;${JAVA_HOME}/lib;${JRE_HOME}/lib
export PATH =${JAVA_HOME}/bin;$PATH

第二种方法:

运行命令:gedit /etc/profile

追加如下代码:

  export JAVA_HOME =/media/pkx/xuexi_1/jdkInstall/jdk1.8.0_73 //java 的安装路径
export JRE_HOME =${JAVA_HOME}/jre
export CLASSPATH =.;${JAVA_HOME}/lib;${JRE_HOME}/lib
export PATH =${JAVA_HOME}/bin;$PATH

使配置文件生效运行

source /etc/profile 命令。重启计算机

            

            

            
















你可能感兴趣的:(ubutun安装jdk和设置环境变量)