Following is a step by step guide to install Java on Linux. In this training, we will install Java on Ubuntu. The process and install commands remain the same, for different flavors of Linux, or versions of Java.
How to Install Oracle Java on Ubuntu Linux
Step 1) Before you start with the setting up Java, you will need to remove the OpenJDK/JRE from the system.
To do this, use below command-
sudo apt-get purge openjdk-\*
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal1.png)
You will be asked for a confirmation. Enter Y
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal2.png)
Wait for sometime for uninstall to complete
Step 2) Check whether Ubuntu OS architecture is 32-bit or 64-bit.
You can do it using the following command-
file /sbin/init
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal3.png)
Step 3) Download latest Java (a zip file e.g., jdk-8-linux-x64.tar.gz) from Oracle site-
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal4.png)
Accept the License Agreement.
- Select x86 for 32-bit system
- Select x64 for 64-bit system
- Select the tar.gz for Ubuntu
- Select rpm for Debian based system
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal5.png)
Once a download is complete you will see
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal6.png)
Step 4) In the terminal, navigate to the location of your zip file
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal7.png)
Extract contents of java zip file in a directory of your choice.
In this tutorial, we will extract in the Downloads folder itself –
sudo tar -xvf jdk-8u5-linux-i586.tar.gz
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal8.png)
Enter your password, if asked. The unzip will continue. Once done you will see the following folder -
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal9.png)
Step 5) Add the following system variables to the end of /etc/profile file
JAVA_HOME=<Directory where JAVA has been extracted>/jdk1.8.0 PATH=$PATH:$HOME/bin:$JAVA_HOME/bin export JAVA_HOME export PATH
To do so –
Enter command
"sudo nano /etc/profile"
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal10.png)
Enter the system variables
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal11.png)
Press Control+C to enter into command mode
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal12.png)
Press ^+X to Exit
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal13.png)
Press "Y" to save the changes
Step 6) Now reload environment using a command,
. /etc/profile
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal14.png)
Step 7) Its time to let Ubuntu know where our JDK/JRE is located.
Copy-paste below lines into a command prompt.
sudo update-alternatives --install "/usr/bin/java" "java" "<Directory where JAVA has been extracted>/bin/java" 1 sudo update-alternatives --install "/usr/bin/javac" "javac" "<Directory where JAVA has been extracted>/bin/javac" 1 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "<Directory where JAVA has been extracted>/bin/javaws" 1
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal15.png)
Step 8) Tell Ubuntu that our installation i.e., jdk1.8.0_05 must be the default Java.
Use below commands to do this-
sudo update-alternatives --set java <Directory where JAVA has been extracted>/bin/java sudo update-alternatives --set javac <Directory where JAVA has been extracted>/bin/javac sudo update-alternatives --set javaws <Directory where JAVA has been extracted>/bin/javaws
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal16.png)
Step 9) Test the installation using below command,
java -version
![How to Install Java On Ubuntu How to Install Java On Ubuntu](https://www.guru99.com/images/Big_Data/061114_1140_HowtoInstal17.png)
A successful installation will show information as seen in the above screenshot.
No comments:
Post a Comment