Ubuntu下配置jdk
一、下载
二、安装JDk
2.1、解压jdk
1.创建一个目录
ln0491@ln0491-virtual-machine:/$ sudo mkdir /usr/local/develoment [sudo] password for ln0491: ln0491@ln0491-virtual-machine:/$ ls /usr/local/ bin develoment etc games include lib man sbin share src ln0491@ln0491-virtual-machine:/$
2.将jdk文件cp到这个目录下
ln0491@ln0491-virtual-machine:/$ sudo cp /home/ln0491/Downloads/jdk-8u31-linux-x64.tar.gz /usr/local/develoment/ ln0491@ln0491-virtual-machine:/$ ls /usr/local/develoment/ jdk-8u31-linux-x64.tar.gz ln0491@ln0491-virtual-machine:/$
3. 解压
sudo tar -zxvf jdk-8u31-linux-x64.tar.gz
4.备份配置文件
cd /home/ln0491/
cp .bashrc .bash_bak
5.编辑配置文件 vi .bashrc
在末尾添加
export JAVA_HOME=/usr/local/develoment/jdk1.8.0_31/
export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
别一种写法:和Windows一样
export JAVA_HOME=/usr/local/develoment/jdk1.8.0_31/ export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
6.为了让更改立即生效,请在终端执行如下命令:
source .bashrc
7.查看jdk版本
ln0491@ln0491-virtual-machine:~$ java -version java version "1.8.0_31" Java(TM) SE Runtime Environment (build 1.8.0_31-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode) ln0491@ln0491-virtual-machine:~$
2.2、 配置环境变量
全局配置:/etc/profile文件中配置:
个人用户配置:/home/用户名/.bashrc :只对这具用户有效
这里用的是个人用户配置,也可以配置/etc/profile文件,使所有用户都有效