• Skip to main content
  • Skip to primary sidebar

Ryan McCormick

Dedicated Dad, Software Engineer and Lover of Coffee

How to Manually Install Java 8 on Ubuntu 18.04 LTS

April 29, 2018 by Ryan McCormick 3 Comments

I recently upgraded to the latest LTS version on my dev machine and needed to install Java. I couldn’t remember exactly what I did last time but knew that I needed to download the tarball from Oracle, save the extracted files somewhere, add the runtime (java), SDK compiler (javac) and webstart (javaws) executables to the ubuntu alternatives list and add a JAVA_HOME refererence for other tools like Gradle.

This post is to document how I did this for future reference, but will hopefully be useful to other people solving the same problem. I understand that there is an apt package that I can add and do it that way but it is not owned, maintained or controlled by Oracle. Because I am who I am, I do it manually. This is my own opinionated approach and it works. This is meant to be a guide, I take zero responsibilty for any problems you may encounter while performing the next few steps. All of that being said, please post questions/comments if you encounter issues.

Lets get started.

Step #1: Download the Java 8 SDK from Oracle.

Because of the speed at which technology changes and Java is headed toward version 10, I am hesitant to share links. This link may or may not work by the time you are reading this. If in the case it no longer works, visit google and search for ‘Java SE Development Kit 8 Downloads’.

Java SE Development Kit 8 Downloads

I chose to download 8u172, Linux x64, the one ending in .tar.gz. If you are running RHEL (Redhat Enterprise Linux), CentOS or Fedora, you should download the rpm and be aware that these instructions won’t work for you at the point of updating the alternatives. This is a guide for Ubuntu.

Step #2: Move tarball to Installation Reference Location.

The subtitle for this section can be deceiving if you are not familiar with how symlinks or references work. But stay with me here.

Create a directory at /usr/lib called jvm-oracle. You will need to use the sudo command as this directory is at root level:

sudo mkdir /usr/lib/jvm-oracle

Copy your tarball over:
sudo cp ~/Downloads/(name of your tarball) /usr/lib/jvm-oracle

Move into the /usr/lib/jvm-oracle and extract your tarball:
Move into: cd /usr/lib/jvm-oracle
Extract: sudo tar -xvzf (name of tarball)

List out the directory contents and find your extracted folder:
ls -al

You should see a directory like ‘jdk1.8.0_172’ which is mine at the time of this article. Move into your dir and the bin folder with cd and list out the contents.
Move to new dir: cd jdk1.8.0_172. Tip: if you type a part of the directory name and hit the tab key, it should auto complete. If it doesn’t, type a little more of it and try hitting tab again.
Move to bin: cd bin
List out Contents: ls -al

This directory (bin) contains all of the executables you will need to reference for updating your alternatives. Get the path to this directory and copy/paste it into gedit or your favorite text editor.

Step #3: Add to Ubuntu Alternatives.

I like to prepare the next three command lines in a text editor so I can just copy/paste them into the command line and hit enter.

Here are mine, double check the jdk directory name before using them.
NOTE: Be sure to paste them into a text editor before pasting to the command line. And paste/execute one line at a time.

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm-oracle/jdk1.8.0_172/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm-oracle/jdk1.8.0_172/bin/javac 1
sudo update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm-oracle/jdk1.8.0_172/bin/javaws 1

Since references are directly symlinked to your path, you should immediately have the ability to check to see if your update-alternatives commands worked.
Java Runtime Version: java -version
Java SDK Compiler Version: javac -version
Java Web Start Version: javaws -version

You should see version output for the above commands when hitting enter after entering each one. If you don’t, re check your update-alternatives commands.

Step #4: Add JAVA_HOME to your environment.

Here is a fancy command that can be used to append a JAVA_HOME to the end of your .bashrc file. If you manually type, be sure to take notice of single quotes versus backticks. This is very important.
echo $'\nJAVA_HOME='`which java` >> ~/.bashrc

Check to make sure it appended:
cat ~/.bashrc

If you need to change anything, open in vim, nano or gedit to fix:
gedit ~/.bashrc

Alternatively, you can add it manually by opening your .bashrc file and setting JAVA_HOME=/usr/bin/java

Close your terminal, reopen a new one and type echo $JAVA_HOME to ensure your environment var has been properly set. If you don’t see /usr/bin/java for output, close all terminal sessions, open a new terminal session and try the echo $JAVA_HOME again. If you are still having issues, check the entry in your .bashrc file again.

If you want to set a system-wide JAVA_HOME, add to your /etc/environment file. Note: Because /etc/environment is under the root path, you will need to use the sudo command before your editor command.

That is all I have folks. Be sure to post questions/comments. Happy coding!

Related

Filed Under: Linux/Unix Tips Tagged With: java 8, jdk, ubuntu 18.04 LTS

Reader Interactions

Comments

  1. Zoy says

    September 12, 2019 at 3:09 pm

    Great! This tutorial saved me so much time with installing oracle java, now that the ready ppa packages are not working anymore die to Oracle license agreement.
    Thanks a lot!

    Reply
  2. Kosha Patel says

    February 19, 2020 at 7:13 pm

    If you want to set a system-wide JAVA_HOME, add to your /etc/environment file. Note: Because /etc/environment is under the root path, you will need to use the sudo command before your editor command.

    It would be of great help if you write about what will be achieved doing this? Also, I want commands for that. Thank you.

    The article was indeed helpful.

    Reply
  3. Pourya says

    April 22, 2020 at 6:26 am

    Finally a practical and working guide to install Java SDK, since Oracle changed the terms and PPA method doesn’t work anymore. I was looking for this for couples of hours on Google.
    Thanks for saving my day.

    Reply

Leave a Reply Cancel reply

Primary Sidebar

Recent Posts

  • Force Quit Kill all Chrome Windows MacOS
  • SOLVED: Angular 6 CLI Karma Stuck in Single Run | Karma Stops Running
  • How to Manually Install Java 8 on Ubuntu 18.04 LTS
  • Remove VirtualBox from Ubuntu 16.04 Xenial
  • Clear all Node Modules Folders Recursively Mac/Linux

Recent Comments

  • KKV on Webstorm adding spaces between imports and braces | JavaScript and TypeScript
  • jusopi on Clear all Node Modules Folders Recursively Mac/Linux
  • Qaisar Irfan on Clear all Node Modules Folders Recursively Mac/Linux
  • mustafa on Remove VirtualBox from Ubuntu 16.04 Xenial
  • Pourya on How to Manually Install Java 8 on Ubuntu 18.04 LTS

Archives

  • May 2019
  • May 2018
  • April 2018
  • March 2018
  • January 2018
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • March 2017
  • December 2015
  • November 2015
  • July 2015
  • April 2015
  • February 2015
  • September 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • October 2013
  • August 2013
  • June 2013
  • April 2013
  • March 2013
  • February 2013
  • December 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • May 2012
  • March 2012
  • February 2012
  • December 2011
  • November 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • August 2009
  • July 2009
  • May 2009

Categories

  • Angular
  • Angular 2
  • AngularJS (1x branch)
  • Computer Q&A
  • ES2015
  • Internet Marketing
  • Javascript
  • Job Interviews
  • Job Search
  • Karma
  • Laravel
  • Linux
  • Linux/Unix Tips
  • MacOS
  • Microsoft Access
  • Microsoft Excel
  • Microsoft Outlook
  • Microsoft Word
  • News
  • Node
  • Open Source
  • PHP
  • Protractor
  • Resume Writing
  • Spring Boot
  • SQL
  • Ubuntu
  • VBA
  • VBScript
  • VirtualBox
  • Web Development
  • Windows Tips
  • Wordpress

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2023 · Magazine Pro on Genesis Framework · WordPress · Log in