These comamnds will install Oracle's JDK 8 (and the JRE 8 browser plugin):
Note that if apt-add-repository gives you a "command not found" error you can add this command via
The remainder of this article is dedicated to the manual download and installation of the JDK. For most users, the automated method shown above should be sufficient. As demonstrated below, verify the installation by typing "java -version" on the terminal session.
- Removing other versions
- Downloading Oracle's JDK
- Where to install?
- Updating the PATH
Removing Other Versions
Ubuntu usually comes installed with OpenJDK. On new installations of Ubuntu, I prefer to uninstall this.
To verify if you have OpenJDK installed, type this on the command line:
OpenJDK can be removed using this command:
Where do I download the JDK?
I start at Oracle’s site here:
Where should I install the JDK?If you are not familiar with the Linux directory layout, this article is recommended:
The JDK should be installed in the “usr” directory. This directory houses all the binaries, documentation, libraries, and header files for all the user applications. Most user binaries will be installed into this folder making this one of the largest folders in the Linux directory.
My preferred path is:
This leaves opportunty to distinguish between JDK and JRE installations, and multiple versions of each.
How do I install the JDK?
Typically, the file will be downloaded to your “downloads” folder in your home directory.
Using a terminal, following these steps:
1. Create the Directory Path
This creates the directory path for the new installation. The -p flag creates the directory hierarchy. You will need to run this command as the super user (su + do = sudo).
2. Move the File
Move the downloaded file to the installation path.
3. Unzip the File
Navigate to the newly created folder, and unpack the downloaded file.
Setting the Path
I recommend setting the path in the /etc/environment file.
This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line.
I've added the italicized text:
To activate these path variables for the current terminal session, type
If your path variables were set successfully, you should be able to type
...and get back something that looks like this:
Permanently Setting the Path
To permanently modify the path, modify the .bashrc file.
.bashrc is a shell script that Bash runs whenever it is started interactively. You can put any command in that file that you could type at the command prompt. You put commands here to set up the shell for use in your particular environment, or to customize things to your preferences.
Follow this command sequence:
when the text editor comes up, add this line (anywhere):
“sudo” privileges are not necessary, since this file is modified on a per-user basis.
To test your changes, exit your current command shell, and type
as you did in the prior example.
- If you make an error when editing the .bashrc file you can send Ubuntu into an infinite logon loop the next time you reboot.
- This article contains more information.
- “No such file or directory” when invoking java
- [Github] Installation Script (based on this article)
- [Blog] Installing Eclipse on Ubuntu 14.04
- [StackExchange] The purpose of .bashrc
- [AskUbuntu] Ubuntu gets stuck in an Infinite Loop
- [Help.Ubuntu] Environment Variables in Ubuntu
- [AskUbuntu] Using a PPA (Personal Package Archive) to install the Oracle JDK
- I've tested this on Ubuntu 14.10 and it works fine (4:43 PM 1/28/2015)
- [AskUbuntu] Uninstalling OpenJDK
- Installing Missing apt-add-repository Command
- [Github] Vagrant Recipe