ubuntu配置java環境

ubuntu系統默認沒有安裝java環境,當運行javac時提示沒有安裝:html

$ javac
The program 'javac' can be found in the following packages:
 * default-jdk
 * ecj
 * gcj-5-jdk
 * openjdk-8-jdk-headless
 * gcj-4.8-jdk
 * gcj-4.9-jdk
 * openjdk-9-jdk-headless
Try: sudo apt install <selected package>

打開oracle官網,java下載地址java

http://www.oracle.com/technetwork/java/javase/downloads/index.htmllinux

根據系統選擇版本,這裏選擇 jdk-8u144-linux-x64.tar.gz(Linux x64 176.92 MB)下載好以後,進行解壓安裝,這裏安裝到/opt/jdk-8目錄下ubuntu

cd /opt/
mkdir jdk1.8.0_144
cd jdk1.8.0_144/
mv /home/muti/Downloads/jdk-8u144-linux-x64.tar.gz  .
tar -zxvf jdk-8u144-linux-x64.tar.gz 
mv jdk1.8.0_144/* .

而後在/etc/profile中新建java環境變量,vim

vim /etc/profile

填寫內容以下oracle

export JAVA_HOME=/opt/jdk1.8.0_144
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME=/usr/jdk1.8.0_144
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

馬上生效less

source /etc/profile

檢查是否正確安裝ui

java -version

輸出spa

# java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
相關文章
相關標籤/搜索