Install Oracle JDK 1.8 and Set environment variables in Ubuntu

Prerequisites:

Steps:

  1. Open the Terminal (Ctrl + Alt + T)
  2. Create the jvm folder in usr/lib
    $ sudo mkdir /usr/lib/jvm
  3. Change the working directory
    $ cd /usr/lib/jvm
  4. Extract the downloaded jdk-xuxxx-linux-x64.tar.gz file in the ~/Downloads folder using this command
    $ sudo tar -xvzf ~/Downloads/jdk-8u211-linux-x64.tar.gz
  5. Open the Environment Variable file using Nano-editor or Vi-editor
    $ sudo nano /etc/environment or $ sudo vi /etc/environment
  6. Add the following ‘bin-folder-path’ to the existing PATH variable in the opened file (ensure to separate the Path variable by a semicolon [:])
    /usr/lib/jvm/jdk-11/bin
  7. Add the following JAVA_HOME environment variables at the end of the file. JAVA_HOME="/usr/lib/jvm/jdk-11"
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.8.0_211/bin"
JAVA_HOME="/usr/lib/jvm/jdk1.8.0_211"
— 8.1 If Nano; 
— — - Ctrl + O and then Ctrl + X
— 8.2 If Vi;
— — - Press Escape.
— — - Then Shift + Semicolon (:).
— — — Afterwards type (:wq!) and Press Enter
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_211/bin/java" 0$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_211/bin/javac" 0$ sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_211/bin/java$ sudo update-alternatives --set javac /usr/lib/jvm/jdk1.8.0_211/bin/javac
$ update-alternatives --list java
$ update-alternatives --list javac
$ sudo vi ~/.bashrc
JAVA_HOME=”/usr/lib/jvm/jdk1.8.0_211"
MAVEN_HOME=”/usr/share/maven”
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$MAVEN_HOME/bin
export JAVA_HOME
export MAVEN_HOME
export PATH
Press Escape. 
Then Shift + Semicolon (:).
Afterwards type (:wq!)
and Press Enter
$ java -version
$ echo $JAVA_HOME

--

--

Writer | Vlogger | Techie | Technical Tester (Snr-QAE)

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store