How to Download & Install Java in Centos, Ubuntu,Redhat and other Linux Operating system

Install java on Linux centos 7

Step by step Java install on Centos 7. The process and install commands are same for different Linux OS.

Step 1. Check Centos OS architecture is 32-bit or 64-bit.

#arch

i386 and i686 are 32-bit

x86_64 is 64-bit

i386 and i686 are 32-bit

Step 2. How to Download Oracle Java on centos 7

1-you need to enter following url in browser or go to Download menu of Oracle site and select your required version

https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

2-Accept License Agreement and download Linux x64 with .tar.gz extencen

Accept License Agreement

Step 3. Extract/unzip tar package

I have download 64-bit jdk8 so my file name is jdk-8u201-linux-x64.tar.gz and Download in /root/Download location 

1-Open terminal (right click on desktop and select terminal) and navigate to location

#cd /root/Download 

2-Extract tar file

#tar -zxf jdk-8u201-linux-x64.tar.gz

Extract tar file

Step 4. Configure Java in Linux

1-Move java package in working Directory and this Demo session I’m Moving in  /usr/local location and its Directories name is java like

#mv /root/Download/jdk1.8.0_201  /usr/local/java

Configure Java in Linux

Note: if are you installing for Hadoop/Bigdata/spark/Cassandra or any other technology specific then maybe you need to change its owner and group so you can use

#chown hduser:hadoop -R /usr/local/java

There hduser is user and hadoop is group keep in mind

hduser

2-befor configuring new version of java just checking running java version and location because Linux default installed java version when Linux install

Check java version

#java -version

It will show like openjdk version “1.8.0_131”

Check running java local

#which java

It will show like /usr/bin/java

Check running java local

3-Open configure file (bashrc file) for add CLASSPATH variable for Java configure

#vim /etc/bashrc

Add below mention 2 lines in file:

export JAVA_HOME=/usr/local/java
export PATH=/usr/local/java/bin:$PATH

configure  bashrc file

4-Reload bash using following commands

#exec bash

Reload bash

5- Now again check running java version and its location it will changed

again check running java version

Your Java installing and Configuration completed 🙂

For Demo and testing purpose Creating demo java class

Create java first program in Linux

1-Create temporary working directory like gehlot in /tmp location

#mkdir /tmp/gehlot

2-Navigate to woirking location

#cd /tmp/gehlot

3-Create and open Simple.java like

#vim Simple.java

Create and open Simple.java like

4-Now past below code Simple.java file

class Simple{ 
          public static void main(String args[]){ 
          System.out.println(“Hello Java”); 
          } 
}       

Simple.java file

5-Compile Simple.java file like

#javac Simple.java

6-Now run compiled Simple file

#java Simple

run compiled Simple file

It’s expecting output will like “Hello Java”

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *