There are JDK versions available from the base CentOS repositories. Depending on your version of CentOS, and the JDK you want to install, the following as root should give you what you want:

OpenJDK Runtime Environment (Java SE 6)

yum install java-1.6.0-openjdk

OpenJDK Runtime Environment (Java SE 7)

yum install java-1.7.0-openjdk

OpenJDK Development Environment (Java SE 7)

yum install java-1.7.0-openjdk-devel

OpenJDK Development Environment (Java SE 6)

yum install java-1.6.0-openjdk-devel

Update for Java 8

In CentOS 6.6 or later, Java 8 is available. Similar to 6 and 7 above, the packages are as follows:

OpenJDK Runtime Environment (Java SE 8)

yum install java-1.8.0-openjdk

OpenJDK Development Environment (Java SE 8)

yum install java-1.8.0-openjdk-devel

There's also a 'headless' JRE package that is the same as the above JRE, except it doesn't contain audio/video support. This can be used for a slightly more minimal installation:

OpenJDK Runtime Environment - Headless (Java SE 8)

yum install java-1.8.0-openjdk-headless
Answer from grdryn on Stack Overflow
๐ŸŒ
OVHcloud
us.ovhcloud.com โ€บ tutorials โ€บ how to install java on centos 7 ?
How to install Java on Centos 7 ?
In this tutorial, you will learn how to install a Java Development Kit (JDK) on the Centos 7 Linux distribution.
Discussions

java - How to install Jdk in centos - Stack Overflow
There are JDK versions available from the base CentOS repositories. Depending on your version of CentOS, and the JDK you want to install, the following as root should give you what you want: ... In CentOS 6.6 or later, Java 8 is available. Similar to 6 and 7 above, the packages are as follows: More on stackoverflow.com
๐ŸŒ stackoverflow.com
rpm - OpenJDK 17 for CentOS 7 - Unix & Linux Stack Exchange
Currently there is no possibility to install java-17-openjdk through sudo yum install java-17-openjdk on a CentOS 7 system (CentOS Linux release 7.9.2009 (Core)) as it was possible some time ago. W... More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
May 23, 2022
java - How to install jdk7 on CentOS? - Stack Overflow
I'm trying to install jdk7 on my CentOS 6.5 machine. Actually, I thought I already did this 6 months ago but when I type java -version I see javac 1.6.0_30. I've downloaded jdk-7u25-linux-x64.tar.gz, verified checksum, then extracted to /home/username/java/jdk7u25/jdk1.7.0_25. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Installing Java to Another Location on Centos 7
JAVA_HOME needs to point to a JDK directory not to a java binary itself. More on reddit.com
๐ŸŒ r/linux4noobs
5
1
August 15, 2022
๐ŸŒ
Ignite Realtime
discourse.igniterealtime.org โ€บ openfire
Cent OS 7 (EOL) how to install Java 1:11.0.0 for 4.8 - Openfire - Ignite Realtime Community Forums
March 1, 2024 - 1st off, I love CentOS but I am original Mac/PC user so I only use Unix on a few servers. Still very much learning each time I deploy or use it. I know I need to replace CentOS and going with Rocky but until that new deployment I need Openfire to work. Trying to update to 4.8 and I get this ...
Top answer
1 of 4
64

There are JDK versions available from the base CentOS repositories. Depending on your version of CentOS, and the JDK you want to install, the following as root should give you what you want:

OpenJDK Runtime Environment (Java SE 6)

yum install java-1.6.0-openjdk

OpenJDK Runtime Environment (Java SE 7)

yum install java-1.7.0-openjdk

OpenJDK Development Environment (Java SE 7)

yum install java-1.7.0-openjdk-devel

OpenJDK Development Environment (Java SE 6)

yum install java-1.6.0-openjdk-devel

Update for Java 8

In CentOS 6.6 or later, Java 8 is available. Similar to 6 and 7 above, the packages are as follows:

OpenJDK Runtime Environment (Java SE 8)

yum install java-1.8.0-openjdk

OpenJDK Development Environment (Java SE 8)

yum install java-1.8.0-openjdk-devel

There's also a 'headless' JRE package that is the same as the above JRE, except it doesn't contain audio/video support. This can be used for a slightly more minimal installation:

OpenJDK Runtime Environment - Headless (Java SE 8)

yum install java-1.8.0-openjdk-headless
2 of 4
38

I advise you to use the same JDK as you may use with Windows: the Oracle one.

http://www.oracle.com/technetwork/java/javase/downloads/index.html
Go to the Java SE 7u67 section and click on JDK7 Download button on the right.

On the new page select the option "(ยค) Accept License Agreement"
Then click on jdk-7u67-linux-x64.rpm

On your CentOS, as root, run:

$ rpm -Uvh jdk-7u67-linux-x64.rpm
$ alternatives --install /usr/bin/java java /usr/java/latest/bin/java 2

You may already have a Java 5 installed on your box... before installing the downloaded rpm remove previous Java by running this command yum remove java

Find elsewhere
๐ŸŒ
InMotion Hosting
inmotionhosting.com โ€บ inmotion hosting home โ€บ support โ€บ product guides โ€บ vps hosting โ€บ how to install java on centos
How to Install Java on CentOS | InMotion Hosting
January 4, 2024 - Java is required for running some games on your Linux VPS including Minecraft. The object-oriented programming language powers many websites and applications on computers and mobile devices. Below we cover how to: ... You need root access to your linux server on your VPS or Dedicated server to continue. ... The installation process consists of installing OpenJDK, the open source Java implementation which includes Font Renderer, or proprietary Oracle JRE/JDK with Flight Recorder which builds on top of OpenJDK.
๐ŸŒ
GitHub
gist.github.com โ€บ smijar โ€บ 3926fa4eb9bc95281b3ba5de93d73ef8
Installing JDK 7 or 8 on centos 7/8 ยท GitHub
Installing JDK 7 or 8 on centos 7/8. GitHub Gist: instantly share code, notes, and snippets.
๐ŸŒ
GitHub
github.com โ€บ sarma1807 โ€บ CentOS-7 โ€บ blob โ€บ master โ€บ Install & Configure Oracle JDK & JRE.md
CentOS-7/Install & Configure Oracle JDK & JRE.md at master ยท sarma1807/CentOS-7
There are 3 programs which provide 'java'. Selection Command ---------------------------------------------------------------------------------------------------------------------- *+ 1 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.71-2.b15.el7_2.x86_64/jre/bin/java (OpenJDK JRE) 2 /usr/java/jdk1.8.0_74/jre/bin/java (JRE part of Oracle JDK) 3 /usr/java/jre1.8.0_74/bin/java (Oracle JRE) Enter to keep the current selection[+], or type selection number: 3
Author ย  sarma1807
๐ŸŒ
Linuxize
linuxize.com โ€บ home โ€บ java โ€บ how to install java on centos 7
How to Install Java on CentOS 7 | Linuxize
February 24, 2020 - If you are not sure which Java implementation and version to install, the general recommendation is to install OpenJDK 11 JDK, which is the current LTS version of Java. Before starting with the tutorial, make sure you are logged in as root or user with sudo privileges . OpenJDK, the open-source implementation of the Java Platform, is the default Java development and runtime in CentOS 7.
๐ŸŒ
Atlantic.Net
atlantic.net โ€บ home โ€บ blog โ€บ how to install java (jre or jdk) on centos 7
How to Install Java (JRE or JDK) on CentOS 7: A Guide | Atlantic.Net
January 9, 2026 - sudo yum install java-1.8.0-openjdk sudo yum install java-1.7.0-openjdk sudo yum install java-1.6.0-openjdk
Top answer
1 of 2
8

You should only be editing your PATH if you have to install a personal copy of Java. If you are going that route then you need to make sure that the bin directory of your preferred version of Java is at the beginning of your PATH, like so:

export JAVA_PATH=$JAVA_HOME
export PATH=$JAVA_HOME/bin:$PATH
export PATH=$JRE_HOME/bin:$PATH

But the better way to handle this is to install Java and use the alternatives command. If you can get by with OpenJDK you could just try:

yum install java-1.7.0-openjdk
yum install java-1.7.0-openjdk-devel

As OpenJDK is installed it will run the alternatives command to correctly configure everything. If you want to use the Oracle JDK then you can use either the RPM or the tar.gz, the RPM installed in /usr/java while the tar.gz should probably be extracted to that directory or another non-user specific directory like /opt/java or something. Personally I'd recommend the RPMs so install would be something like:

yum localinstall jdk-8u5-linux-x64.rpm
yum localinstall jdk-8u5-linux-x64-demos.rpm

After install comes the alternatives command however most people and docs get lazy (look at the CentOS wiki page that the other answer points to for an example of what I mean by lazy). You really should use the alternatives command to setup not only java and javac but also all the other commands that come with Java AND the man pages for those commands. You should run like:

jdk=/usr/java/jdk1.8.0_05
jre=$jdk/jre

alternatives \
  --install /usr/bin/java java $jre/bin/java 180005 \
  --slave /usr/lib/jvm/jre jre $jre \
  --slave /usr/bin/keytool keytool $jre/bin/keytool \
  --slave /usr/bin/orbd orbd $jre/bin/orbd \
  --slave /usr/bin/pack200 pack200 $jre/bin/pack200 \
  --slave /usr/bin/rmid rmid $jre/bin/rmid \
  --slave /usr/bin/rmiregistry rmiregistry $jre/bin/rmiregistry \
  --slave /usr/bin/servertool servertool $jre/bin/servertool \
  --slave /usr/bin/tnameserv tnameserv $jre/bin/tnameserv \
  --slave /usr/bin/unpack200 unpack200 $jre/bin/unpack200 \
  --slave /usr/bin/javaws javaws $jre/bin/javaws \
  --slave /usr/bin/jjs jjs $jre/bin/jjs \
  --slave /usr/share/man/man1/java.1 java.1 \
  $jdk/man/man1/java.1 \
  --slave /usr/share/man/man1/keytool.1 keytool.1 \
  $jdk/man/man1/keytool.1 \
  --slave /usr/share/man/man1/orbd.1 orbd.1 \
  $jdk/man/man1/ordb.1 \
  --slave /usr/share/man/man1/pack200.1 pack200.1 \
  $jdk/man/man1/pack200.1 \
  --slave /usr/share/man/man1/rmid.1 rmid.1 \
  $jdk/man/man1/rmid.1 \
  --slave /usr/share/man/man1/rmiregistry.1 rmiregistry.1 \
  $jdk/man/man1/rmiregistry.1 \
  --slave /usr/share/man/man1/servertool.1 servertool.1 \
  $jdk/man/man1/servertool.1 \
  --slave /usr/share/man/man1/tnameserv.1 tnameserv.1 \
  $jdk/man/man1/tnameserv.1 \
  --slave /usr/share/man/man1/unpack200.1 unpack200.1 \
  $jdk/man/man1/unpack200.1 \
  --slave /usr/share/man/man1/javaws.1 javaws.1 \
  $jdk/man/man1/javaws.1 \
  --slave /usr/share/man/man1/jjs.1 jjs.1 \
  $jdk/man/man1/jjs.1

alternatives \
  --install /usr/lib/jvm/jre-1.8.0 \
  jre_1.8.0 $jre 180005 \

alternatives \
  --install /usr/bin/javac javac $jdk/bin/javac 180005 \
  --slave /usr/lib/jvm/java java_sdk $jdk \
  --slave /usr/bin/appletviewer appletviewer $jdk/bin/appletviewer \
  --slave /usr/bin/extcheck extcheck $jdk/bin/extcheck \
  --slave /usr/bin/idlj idlj $jdk/bin/idlj \
  --slave /usr/bin/jar jar $jdk/bin/jar \
  --slave /usr/bin/jarsigner jarsigner $jdk/bin/jarsigner \
  --slave /usr/bin/javadoc javadoc $jdk/bin/javadoc \
  --slave /usr/bin/javafxpackager javafxpackager $jdk/bin/javafxpackager \
  --slave /usr/bin/javah javah $jdk/bin/javah \
  --slave /usr/bin/javap javap $jdk/bin/javap \
  --slave /usr/bin/jcmd jcmd $jdk/bin/jcmd \
  --slave /usr/bin/jconsole jconsole $jdk/bin/jconsole \
  --slave /usr/bin/jdb jdb $jdk/bin/jdb \
  --slave /usr/bin/jdeps jdeps $jdk/bin/jdeps \
  --slave /usr/bin/jhat jhat $jdk/bin/jhat \
  --slave /usr/bin/jinfo jinfo $jdk/bin/jinfo \
  --slave /usr/bin/jmap jmap $jdk/bin/jmap \
  --slave /usr/bin/jmc jmc $jdk/bin/jmc \
  --slave /usr/bin/jps jps $jdk/bin/jps \
  --slave /usr/bin/jrunscript jrunscript $jdk/bin/jrunscript \
  --slave /usr/bin/jsadebugd jsadebugd $jdk/bin/jsadebugd \
  --slave /usr/bin/jstack jstack $jdk/bin/jstack \
  --slave /usr/bin/jstat jstat $jdk/bin/jstat \
  --slave /usr/bin/jstatd jstatd $jdk/bin/jstatd \
  --slave /usr/bin/jvisualvm jvisualvm $jdk/bin/jvisualvm \
  --slave /usr/bin/native2ascii native2ascii $jdk/bin/native2ascii \
  --slave /usr/bin/policytool policytool $jdk/bin/policytool \
  --slave /usr/bin/rmic rmic $jdk/bin/rmic \
  --slave /usr/bin/schemagen schemagen $jdk/bin/schemagen \
  --slave /usr/bin/serialver serialver $jdk/bin/serialver \
  --slave /usr/bin/wsgen wsgen $jdk/bin/wsgen \
  --slave /usr/bin/wsimport wsimport $jdk/bin/wsimport \
  --slave /usr/bin/xjc xjc $jdk/bin/xjc \
  --slave /usr/share/man/man1/appletviewer.1 appletviewer.1 \
  $jdk/man/man1/appletviewer.1 \
  --slave /usr/share/man/man1/extcheck.1 extcheck.1 \
  $jdk/man/man1/extcheck.1 \
  --slave /usr/share/man/man1/idlj.1 idlj.1 \
  $jdk/man/man1/idlj.1 \
  --slave /usr/share/man/man1/jar.1 jar.1 \
  $jdk/man/man1/jar.1 \
  --slave /usr/share/man/man1/jarsigner.1 jarsigner.1 \
  $jdk/man/man1/jarsigner.1 \
  --slave /usr/share/man/man1/javac.1 javac.1 \
  $jdk/man/man1/javac.1 \
  --slave /usr/share/man/man1/javadoc.1 javadoc.1 \
  $jdk/man/man1/javadoc.1 \
  --slave /usr/share/man/man1/javafxpackager.1 javafxpackager.1 \
  $jdk/man/man1/javafxpackager.1 \
  --slave /usr/share/man/man1/javah.1 javah.1 \
  $jdk/man/man1/javah.1 \
  --slave /usr/share/man/man1/javap.1 javap.1 \
  $jdk/man/man1/javap.1 \
  --slave /usr/share/man/man1/jcmd.1 jcmd.1 \
  $jdk/man/man1/jcmd.1 \
  --slave /usr/share/man/man1/jconsole.1 jconsole.1 \
  $jdk/man/man1/jconsole.1 \
  --slave /usr/share/man/man1/jdb.1 jdb.1 \
  $jdk/man/man1/jdb.1 \
  --slave /usr/share/man/man1/jdeps.1 jdeps.1 \
  $jdk/man/man1/jdeps.1 \
  --slave /usr/share/man/man1/jhat.1 jhat.1 \
  $jdk/man/man1/jhat.1 \
  --slave /usr/share/man/man1/jinfo.1 jinfo.1 \
  $jdk/man/man1/jinfo.1 \
  --slave /usr/share/man/man1/jmap.1 jmap.1 \
  $jdk/man/man1/jmap.1 \
  --slave /usr/share/man/man1/jmc.1 jmc.1 \
  $jdk/man/man1/jmc.1 \
  --slave /usr/share/man/man1/jps.1 jps.1 \
  $jdk/man/man1/jps.1 \
  --slave /usr/share/man/man1/jrunscript.1 jrunscript.1 \
  $jdk/man/man1/jrunscript.1 \
  --slave /usr/share/man/man1/jsadebugd.1 jsadebugd.1 \
  $jdk/man/man1/jsadebugd.1 \
  --slave /usr/share/man/man1/jstack.1 jstack.1 \
  $jdk/man/man1/jstack.1 \
  --slave /usr/share/man/man1/jstat.1 jstat.1 \
  $jdk/man/man1/jstat.1 \
  --slave /usr/share/man/man1/jstatd.1 jstatd.1 \
  $jdk/man/man1/jstatd.1 \
  --slave /usr/share/man/man1/jvisualvm.1 jvisualvm.1 \
  $jdk/man/man1/jvisualvm.1 \
  --slave /usr/share/man/man1/native2ascii.1 native2ascii.1 \
  $jdk/man/man1/native2ascii.1 \
  --slave /usr/share/man/man1/policytool.1 policytool.1 \
  $jdk/man/man1/policytool.1 \
  --slave /usr/share/man/man1/rmic.1 rmic.1 \
  $jdk/man/man1/rmic.1 \
  --slave /usr/share/man/man1/schemagen.1 schemagen.1 \
  $jdk/man/man1/schemagen.1 \
  --slave /usr/share/man/man1/serialver.1 serialver.1 \
  $jdk/man/man1/serialver.1 \
  --slave /usr/share/man/man1/wsgen.1 wsgen.1 \
  $jdk/man/man1/wsgen.1 \
  --slave /usr/share/man/man1/wsimport.1 wsimport.1 \
  $jdk/man/man1/wsimport.1 \
  --slave /usr/share/man/man1/xjc.1 xjc.1 \
  $jdk/man/man1/xjc.1

alternatives \
  --install /usr/lib/jvm/java-1.8.0 \
  java_sdk_1.8.0 $jdk 180005 \

That is my example for JDK 8 but if you swap out the jdk= line for your path that will come close but there are a couple of new commands that come with 8 and one that was dropped from 8 so some slight adjustments would be needed if you really wanted to install 7. Also note the 1800005 number. With the alternatives command the higher number is the default selection and OpenJDK 7u55 uses 170055. If you pick a number lower than the number used by whatever OpenJDK you have installed you'll need to run alternatives --config java and alternatives --config javac.

After running the alternatives commands you want to update you man page keyword database by running makewhatis.

Then you might want to install the Java plugin for your Firefox:

ln -s /usr/java/jdk1.8.0_05/jre/lib/amd64/libnpjp2.so /usr/lib64/mozilla/plugins/

Then you'd want to add the Java Control Panel to your System->Preferences menu and setup JARs to be double-clicked on:

/bin/cp -fr /usr/java/jdk1.8.0_05/jre/lib/desktop/* /usr/share/
/bin/cp -fr /usr/java/jdk1.8.0_05/jre/lib/desktop/icons/hicolor/* /usr/share/icons/System
/usr/bin/gtk-update-icon-cache -f /usr/share/icons/System
/usr/bin/update-desktop-database

If it wasn't clear, you'd do all this as root. If you don't have root then just use the tar.gz version and fix your PATH. I wrote a little bit more detail at http://blog.osdev.org/java/2014/04/22/jdk-alternatives.html

2 of 2
0

You probably has link in /usr/bin/java to your another java installation directory.

Check there about alternatives in CentOS

๐ŸŒ
Reddit
reddit.com โ€บ r/linux4noobs โ€บ installing java to another location on centos 7
r/linux4noobs on Reddit: Installing Java to Another Location on Centos 7
August 15, 2022 -

Hello,

I installed java before and i am running java applications on Centos, it is located at /usr/bin/java. For some other reason i want to install it to another location, let's say /myDirectory/java I downloaded java jdk as tar file and extract it to /myDirectory this directory then i set JAVA_HOME accordingly.

The problem is i can't start the applications anymore, the log says :

ERROR: JAVA_HOME is set to an invalid directory: /myDirectory/jdk1.8.0_181/bin/java

Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

Is it because i had a prior installation? How do i achive this? Any help would be aprreciated, thanks.

๐ŸŒ
PhoenixNAP
phoenixnap.com โ€บ home โ€บ kb โ€บ sysadmin โ€บ how to install java on centos and rocky linux
How to Install Java on CentOS and Rocky Linux
December 16, 2025 - Install Java on CentOS and Rocky Linux with this tutorial. Also, learn to change the default version and set the environment variable.
๐ŸŒ
Linode
linode.com โ€บ docs โ€บ guides โ€บ install-java-on-centos
Install Java on Centos 7 | Linode Docs
June 1, 2017 - This guide shows how to install the OpenJDK 8 runtime environment to support Java app execution and development on a Linode running CentOS 7.