Install JDK
Download JDK
- Visit to Oracle Java SE download page.
- Download JDK for Linux 64 such as jdk-8u91-linux-x64.tar.gz.
Check if we have Java installed on our system
- Open the Terminal
- Type java -version.
If we have OpenJDK installed:
java version "1.7.0_15" OpenJDK Runtime Environment (IcedTea6 1.10pre) (7b15~pre1-0lucid1) OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
Copy .gz to destination folder
cd /home/"our_user_name"/Downloads
such ascd /home/yen/Downloads
.sudo cp -r jdk-8u91-linux-x64.tar.gz /usr/local/java
Unpack the .gz
cd /usr/local/java
sudo tar xvzf jdk-8u91-linux-x64.tar.gz
Edit the system PATH file
sudo gedit /etc/profile
- Scroll down to the end of the file.
- add the following lines below:
JAVA_HOME=/usr/local/java/jdk1.8.0_91 JRE_HOME=$JAVA_HOME/jre PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin export JAVA_HOME export JRE_HOME export PATH
Inform system where the Oracle Java JDK/JRE is
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_91/bin/java" 1 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_91/bin/javac" 1 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_91/bin/javaws" 1
Set it to be default
sudo update-alternatives --set java /usr/local/java/jdk1.8.0_91/bin/java sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_91/bin/javac sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_91/bin/javaws
Reload system wide PATH /etc/profile
source /etc/profile
Double check
java -version
java version "1.8.0_91" Java(TM) SE Runtime Environment (build 1.8.0_91-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
javac -version
javac 1.8.0_91
- We can write a simple java class to test.
Restart Ubuntu