These comamnds will install Oracle's JDK 8 (and the JRE 8 browser plugin):
sudo apt-add-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java8-installer
Note that if apt-add-repository gives you a "command not found" error you can add this command via
sudo apt-get install software-properties-common python-software-properties
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:
sudo apt-get purge openjdk* sudo apt-get autoremove
Where do I download the JDK?
I start at Oracle’s site here:
http://www.oracle.com/technetwork/java/javase/downloads/index.htmlAnd for this article, I’ve selected the latest JDK (1.0.8_31).
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:
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
sudo mkdir -p /usr/lib/jvm/jdk/
2. Move the File
sudo mv ~/Downloads/jdk-8u31-linux-x64.tar.gz /usr/lib/jvm/jdk/
3. Unzip the File
cd /usr/lib/jvm/jdk/ sudo tar -zxvf jdk-8u31-linux-x64.tar.gz
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.
sudo gedit /etc/environment
I've added the italicized text:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk/1.8.0_31/bin/ export PATH export JAVA_HOME=/usr/lib/jvm/jdk/1.8.0_31
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:
craigtrim@CVB:~$ java -version java version "1.8.0_31" Java(TM) SE Runtime Environment (build 1.8.0_31-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
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):
To test your changes, exit your current command shell, and type
- 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
- [StackOverflow] Solution 1, Solution 2
- Summary: 32-bit libraries are missing
I was able to solve this using the StackOverflow link by running:
apt-get install libc6-i386
- [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
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai..ReplyDelete
Excellent information with unique content and it is very useful Blog.ReplyDelete
DevOps Online Training
Great work! I'm glad that I found your post. Keep us updated. DevOps Training in Chennai | DevOps Training in anna nagar | DevOps Training in omr | DevOps Training in porur | DevOps Training in tambaram | DevOps Training in velacheryReplyDelete