Hamsa K
4 min read | 5 years ago

Install Java 12 on centos 7

Install Java 12 on centos 7

Java 12 has been released for general availability with the many featured enhancements. You can read the details in this page.

Step 1: Download Java12

Download the latest Java SE Development Kit 12 LTS release from its official download url

### Oracle Java JDK 12 ###
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647
### Oracle Java JDK 11 ###
### Oracle Java JDK 8 ###

Step 2: Installing Java

[root@lampblogs ~]# yum localinstall jdk-12.0.1_linux-x64_bin.rpm

Now the JDK should be installed at /usr/java/jdk-12.0.1

Step 3: check java version

[root@lampblogs ~]# java -version
java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)

step 4: set environment variables

If you want to set JAVA_HOME environment variable for a particular user then you can add JAVA_HOME in ~/.bash_profile or if you want to setup for all the users globally then you can add it to /etc/profile file.

[root@lampblogs jdk-12.0.1]# vi ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
# User specific environment and startup programs
export JAVA_HOME=/usr/java/jdk-12.0.1/
export PATH=$PATH:$JAVA_HOME/bin

Now run source ~/.bash_profile

[root@lampblogs ~]# source ~/.bash_profile

If you added /etc/profile then use "source /etc/profile" 

Step5: Test the $JAVA_HOME and $PATH

[root@lampblogs ~]# echo $JAVA_HOME
[root@lampblogs ~]# echo $PATH

Step 6: Multiple JDK installed

If your system had multiple JDK, you can use the alternatives command to set the default Java

[root@lampblogs ~]# alternatives --config java
There are 2 programs which provide 'java'.
  Selection    Command
   1           /usr/java/jdk1.8.0_211-amd64/jre/bin/java
*+ 2           /usr/java/jdk-12.0.1/bin/java
Enter to keep the current selection[+], or type selection number: 

Thats it! Now you can download your favorite IDE like eclipse,NetBeans etc.

Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy