一、下載jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html二、安裝JDk2.1、解壓jdk1.創建一個目錄ln0491@ln0491-virtual-machine:/$ su...
一、下載
二、安裝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文件,使所有用戶都有效