一、準備要放JDK的路徑
cd /usr/local
sudo mkdir java
二、將檔案解壓縮
cd /usr/local/java
sudo tar xzvf ~/Downloads/jdk-8u31-linux-x64.tar.gz
三、Ubuntu更新JDK8安裝位置
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_31/jre/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_31/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_31/jre/bin/javaws" 1
sudo update-alternatives --set java /usr/local/java/jdk1.8.0_31/jre/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_31/bin/javac
sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_31/jre/bin/javaws
查看路徑是否設定成功
cd /usr/bin
ls -ld java*以下訊息:
lrwxrwxrwx 1 root root 22 Mar 31 20:41 java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 23 Mar 31 20:42 javac -> /etc/alternatives/javac
lrwxrwxrwx 1 root root 24 Mar 31 20:42 javaws -> /etc/alternatives/javaws
cd /etc/alternatives
ls -ld java*以下訊息:
lrwxrwxrwx 1 root root 40 Aug 29 18:18 java -> /usr/local/java/jdk1.8.0_20/jre/bin/java
lrwxrwxrwx 1 root root 37 Aug 29 18:18 javac -> /usr/local/java/jdk1.8.0_20/bin/javac
lrwxrwxrwx 1 root root 42 Aug 29 18:19 javaws -> /usr/local/java/jdk1.8.0_20/jre/bin/javaws
查看java版本與路徑
javac -version
java -version
which javac
which java
四、設定JAVA PATH跟JAVA HOME
cd /etc
sudo vim profile
export JAVA_HOME=/usr/local/java/jdk1.8.0_31 export PATH=$JAVA_HOME/bin:$PATH儲存後離開
source /etc/profile
echo $JAVA_HOME
echo $PATH
參考鍵結:https://www3.ntu.edu.sg/home/ehchua/programming/howto/Ubuntu_HowTo.html#jdk
沒有留言:
張貼留言