Java is the prominent source to assist in developing and executing the applications or programs written in the Java language. The maker of Java is “Sun Microsystems” but now it is under “Oracle”. If we talk about its implementation, it is available in various suite such as Openjdk, Oracle Java, etc.
Here, we will discuss about how to download and install Oracle Java in Ubuntu. Now the question arises, why is it so? The major difference between the above two are:
- Openjdk is a open source while the Oracle java is an implementation of it.
- When it comes to the stability, Oracle java/ jdk is more stable than Openjdk.
- The most important thing is how you are going to use it: If you want to use it for small program or for personal use then it is fine to use Openjdk. However, in need to build application for the commercial use then you must go for Oracle Java. As in Openjdk you may find the fatal errors and sometimes it crashes, which is not suitable for building the large applications.
We have explored enough for choosing Oracle Java to install. In addition to that Oracle Java Standard Edition comes with the Java Development Kit (JDK) + JavaFX Software Development Kit (SDK) + Java Runtime Environment (JRE) and many other tools.
Steps to Download and Install Oracle Java in Ubuntu
Step 1: For downloading the Oracle Java you need to visit the website www.oracle.com.
Go to the Downloads tab and click on it.
Step 2: Check for the Java Downloads. Click on it, you will find the latest edition at the top i.e. Java SE 8u31. To download the Java Development Kit (JDK), hit on the “Download” button below it.
Step 3: It will take some time to load, meanwhile open up the “Terminal” in your Ubuntu machine by pressing “Ctrl + Alt + T”. Then write the command “cd Downloads”, by default, the JDK will be stored in the download folder.
Step 4: Check out the browser, whether you have redirected to the next page or not. As you can see in the figure, it’s done. So, I will choose “tar” file for Linux based system such as Ubuntu. But, be careful while selecting the Linux x64 or Linux 32 bit.
If your system is of 32 bit OS, download the Linux32 based zipped file and if, 64 bit so download Linux x64 file. In my case, it’s 64 bit, so I choose Linux x64 corresponding file.
For an example: If you try to install Linux x64 file on 32-bit Operating system, the system will encounter multiple errors and you would not be able to accomplish the task.
Step 5: Once you click on “tar” file, downloading will get started. You”ll asked to save it, so click on “Save File” when a dialog box appears, click on“OK” button to proceed.
Step 6: It will take few minutes depending upon your system’s Internet connectivity. Once it is complete, unzip the “tar” file. For that go to the terminal again and type the command “tar -xvf <filename>” such as “tar -xvf jdk-8u31-linux-x64.tar.gz” and press enter.
Step 7: As you can see in the figure below, the file is now unzipped .
Step 8: Now my Terminal window is almost full, so in this case type: “clear” and press enter. “Clear”command is used to clean the terminal screen.
Step 9: Make sure you are at “Downloads” path. Here, type “ls” command to check that JDK folder is created or not.
As you can see in the figure, it’s done.
Step 10: You are now required to check the path named “usr/lib/java”. For that, search the file under “My Computer”.
In my case, I found that there is no folder named “Java”.
Step 11: If you are having the same scenario,then let’s create a folder inside the desired path.
Firstly, you have to change the path, so type: “cd /usr/lib”.
Step 12: After changing the Directory, type: “sudo mkdir java”. This will create a folder named java inside the path “usr/lib”. mkdir command is used to create a directory, as you may know that folders in a Windows OS is termed as “Directories” in Linux Operating system.
Step 13: Done with that..great, now move to the path “usr/lib/java”. But, here you are already at usr/lib so you just need to change a single directory.
Simply type “cd java”, so that you may move to the desired path. This is done to ensure that the directory is successfully created.
Step 14: To store the jdk folder inside the path which we are discussing above, you have to go to the “Downloads” where it is stored for now. You may find that you are in multiple directories, so to go directly to the downloads use the command “cd ~/Downloads”, it will lead you to the destination mentioned, irrespective of the present location.
Step 15: Now type “sudo mv jdk1.8.0_31 /usr/lib/java” to move jdk folder to the destination /usr/lib/java, where “mv” stands for move.
This is done to properly store it in a particular path, that will be easy to search, as you will copy and paste it in Windows.
Step 16: To cross check that the operation you have performed earlier is successfully done or not. Change the path from Downloads to “/usr/lib/java/jdk1.8.0_31/bin” For that type: “cd /usr/lib/java/jdk1.8.0_31/bin” where jdk1.8.0_31 is a folder of jdk with it’s version.
It may differ, if you have downloaded any other version of Java.
Step 17: If done with that, just type “ls” command to list all the items stored in the desired destination. I have performed the same and got the output as shown below.
Step 18: If you have multiple Java installed on your system for an example “openjdk”. So you need to instruct the system which one to use as default.
For that, firstly move one step back, type “cd ..” to go single step back in order to change the directory.
Step 19: Now you are at the path “usr/lib/java/jdk1.8.0_31”. Then update the “alternatives” which is used to tell the system which command to use as a default.
Just type sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/java/jdk1.8.0_31/bin/java” 1 and press enter. This is used for setting the “java” as an alternative.
Step 20: After that do the same for the Java compiler as well i.e. “javac”. Type: sudo update-alternatives –install “/usr/bin/javac” “javac” “/usr/lib/jvm/jdk1.7.0_45/bin/javac” 1 and press enter.
You have done it.
Step 21: Then return to the home path by giving the command: “cd ~”.
Step 22: After this you have to edit the “bashrc” file. You may be thinking of what is bash? It stands for Bourne again shell, improved version of Bourne or sh shell. It is a command line interpreter that works with a text window and reads the instruction given in “.bashrc” file or standard input to execute it.
So, to edit bash file you can use any of the editor such as vim or gedit. Here, I am editing it with “gedit”, the basic text editor in Ubuntu. To open “bashrc” file with gedit type: “sudo gedit ~./bashrc”, by default, by default, it is present in the home directory that’s why used “~” sign, referring to the home directory.
Step 23: Now, file will open up. Insert the lines mentioned below and save it using the “Save” option at the top:
#JAVA HOME DIRECTORY SETUP
Step 24: Hey, people finally you have configured the “Oracle Java” in your Ubuntu system. It’s time to test it, simply type “java”. You”ll get to see its usage and options that ensures it has successfully downloaded and installed.
Step 25: Want to check the version of Java which you have installed, type “java -version”. The output will appear on your screen.
NOTE: The above steps are discussed in brief so you may not come across any difficulty. Don’t get frustrated by just looking at these too many steps. I could have reduced it, but just for your safety , I didn’t.