Install Java on CentOS/Fedora
Installing Java on both CentOS and Fedora are quite similar, since they both supports YUM for their package management and installer tool.
Install OpenJDK 12 on Fedora 30 /CentOS 7
You can use yum search to search for the openjdk version you are planning to install.
$ yum search openjdk
In Fedora, you can search for java-latest-openjdk keyword and you should be able to find “java-latest-openjdk.x86_64 : OpenJDK Runtime Environment 12” if you are going to install 64-bit JDK or you can go for 32-bit JDK with “java-latest-openjdk.i686 : OpenJDK Runtime Environment 12”. Here is the command to install 64-bit on Fedora
$ yum install java-latest-openjdk.x86_64
YUM shows you a confirmation text with a transaction summary of the openjdk dependencies packages are being installed as pre-requisite packages for openjdk.
Last metadata expiration check: 0:02:33 ago on Sat 06 Jul 2019 11:15:09 AM EDT. Dependencies resolved. Package Architecture Version Repository Size Installing: java-latest-openjdk x86_64 1:12.0.1.12-1.rolling.fc30 updates 223 k Installing dependencies: gtk-update-icon-cache x86_64 3.24.9-1.fc30 updates 31 k java-latest-openjdk-headless x86_64 1:12.0.1.12-1.rolling.fc30 updates 39 M libtiff x86_64 4.0.10-5.fc30 updates 167 k adwaita-cursor-theme noarch 3.32.0-1.fc30 fedora 644 k adwaita-icon-theme noarch 3.32.0-1.fc30 fedora 11 M at-spi2-atk x86_64 2.32.0-1.fc30 fedora 78 k ... xorg-x11-fonts-Type1 noarch 7.5-21.fc30 fedora 517 k Installing weak dependencies: gtk3 x86_64 3.24.9-1.fc30 updates 4.5 M dconf x86_64 0.32.0-1.fc30 fedora 94 k Transaction Summary Install 48 Packages Total download size: 60 M Installed size: 257 M Is this ok [y/N]:
You can type y character and enter to accept to proceed installation. It will start downloading the dependencies like this:
Is this ok [y/N]: y Downloading Packages: (1/48): gtk-update-icon-cache-3.24.9-1.fc30.x86_64.rpm 150 kB/s | 31 kB 00:00 (2/48): java-latest-openjdk-12.0.1.12-1.rolling.fc30.x86_64.rpm 591 kB/s | 223 kB 00:00 (3/48): libtiff-4.0.10-5.fc30.x86_64.rpm 1.8 MB/s | 167 kB 00:00 (4/48): gtk3-3.24.9-1.fc30.x86_64.rpm 5.8 MB/s | 4.5 MB 00:00 (5/48): adwaita-cursor-theme-3.32.0-1.fc30.noarch.rpm 1.9 MB/s | 644 kB 00:00 ...
And it might prompt you to proceed for certain packages if they need GPG Key updating. You can have a switch of -y for auto confirmation of those pauses.
(47/48): xorg-x11-fonts-Type1-7.5-21.fc30.noarch.rpm 2.6 MB/s | 517 kB 00:00 (48/48): java-latest-openjdk-headless-12.0.1.12-1.rolling.fc30.x86_64.rpm 10 MB/s | 39 MB 00:03 Total 12 MB/s | 60 MB 00:05 warning: /var/cache/dnf/updates-d6521d96a82a4d6a/packages/gtk-update-icon-cache-3.24.9-1.fc30.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID cfc659b9: NOKEY Fedora 30 - x86_64 - Updates 109 kB/s | 1.6 kB 00:00 Importing GPG key 0xCFC659B9: Userid : "Fedora (30) fedora-30-primary@fedoraproject.org" Fingerprint: F1D8 EC98 F241 AAF2 0DF6 9420 EF3C 111F CFC6 59B9 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-30-x86_64 Is this ok [y/N]:
Type y character again and enter and you will see the installing progress like.
Total 12 MB/s | 60 MB 00:05 warning: /var/cache/dnf/updates-d6521d96a82a4d6a/packages/gtk-update-icon-cache-3.24.9-1.fc30.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID cfc659b9: NOKEY Fedora 30 - x86_64 - Updates 109 kB/s | 1.6 kB 00:00 Importing GPG key 0xCFC659B9: Userid : "Fedora (30) fedora-30-primary@fedoraproject.org" Fingerprint: F1D8 EC98 F241 AAF2 0DF6 9420 EF3C 111F CFC6 59B9 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-30-x86_64 Is this ok [y/N]: y Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Running scriptlet: copy-jdk-configs-3.7-3.fc30.noarch 1/1 Running scriptlet: java-latest-openjdk-headless-1:12.0.1.12-1.rolling.fc30.x86_64 1/1 Preparing : 1/1 Installing : libjpeg-turbo-2.0.2-1.fc30.x86_64 1/48 Installing : libXfixes-5.0.3-9.fc30.x86_64 2/48 Installing : libwayland-client-1.17.0-1.fc30.x86_64 3/48 Installing : libXi-1.7.9-9.fc30.x86_64 ...
And after installing each package and verifying their installation
... Verifying : rest-0.8.1-5.fc30.x86_64 44/48 Verifying : ttmkfdir-3.0.9-56.fc30.x86_64 45/48 Verifying : tzdata-java-2019a-1.fc30.noarch 46/48 Verifying : xorg-x11-font-utils-1:7.5-41.fc30.x86_64 47/48 Verifying : xorg-x11-fonts-Type1-7.5-21.fc30.noarch 48/48 Installed: java-latest-openjdk-1:12.0.1.12-1.rolling.fc30.x86_64 gtk3-3.24.9-1.fc30.x86_64 dconf-0.32.0-1.fc30.x86_64 gtk-update-icon-cache-3.24.9-1.fc30.x86_64 java-latest-openjdk-headless-1:12.0.1.12-1.rolling.fc30.x86_64 libtiff-4.0.10-5.fc30.x86_64 adwaita-cursor-theme-3.32.0-1.fc30.noarch adwaita-icon-theme-3.32.0-1.fc30.noarch at-spi2-atk-2.32.0-1.fc30.x86_64 at-spi2-core-2.32.1-2.fc30.x86_64 atk-2.32.0-1.fc30.x86_64 colord-libs-1.4.4-1.fc30.x86_64 copy-jdk-configs-3.7-3.fc30.noarch fribidi-1.0.5-2.fc30.x86_64 gdk-pixbuf2-modules-2.38.1-1.fc30.x86_64 graphite2-1.3.10-7.fc30.x86_64 harfbuzz-2.3.1-1.fc30.x86_64 hicolor-icon-theme-0.17-5.fc30.noarch jasper-libs-2.0.14-8.fc30.x86_64 javapackages-filesystem-5.3.0-4.fc30.noarch jbigkit-libs-2.1-16.fc30.x86_64 lcms2-2.9-5.fc30.x86_64 libXcomposite-0.4.4-16.fc30.x86_64 libXcursor-1.1.15-5.fc30.x86_64 libXdamage-1.1.4-16.fc30.x86_64 libXfixes-5.0.3-9.fc30.x86_64 libXft-2.3.2-12.fc30.x86_64 libXi-1.7.9-9.fc30.x86_64 libXinerama-1.1.4-3.fc30.x86_64 libXrandr-1.5.1-9.fc30.x86_64 libXtst-1.2.3-9.fc30.x86_64 libdatrie-0.2.9-9.fc30.x86_64 libepoxy-1.5.3-2.fc30.x86_64 libfontenc-1.1.3-10.fc30.x86_64 libgusb-0.3.0-4.fc30.x86_64 libjpeg-turbo-2.0.2-1.fc30.x86_64 libthai-0.1.28-2.fc30.x86_64 libwayland-client-1.17.0-1.fc30.x86_64 libwayland-cursor-1.17.0-1.fc30.x86_64 libwayland-egl-1.17.0-1.fc30.x86_64 lua-5.3.5-5.fc30.x86_64 lua-posix-33.3.1-13.fc30.x86_64 pango-1.43.0-3.fc30.x86_64 rest-0.8.1-5.fc30.x86_64 ttmkfdir-3.0.9-56.fc30.x86_64 tzdata-java-2019a-1.fc30.noarch xorg-x11-font-utils-1:7.5-41.fc30.x86_64 xorg-x11-fonts-Type1-7.5-21.fc30.noarch Complete!
You can check the version of the java installed using java -version
$ java -version openjdk version "12.0.1" 2019-04-16 OpenJDK Runtime Environment 19.3 (build 12.0.1+12) OpenJDK 64-Bit Server VM 19.3 (build 12.0.1+12, mixed mode, sharing)
Install Java SE (Oracle JDK) 12 on Fedora 30 / CentOS 7
Installing Java SE or Oracle JDK on Fedora/CentOS is partially manual. That means you need to download the .rpm package manually using a downloader cli tool like wget:
$ wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.rpm"
Here is the log if the download is successful. Make sure the size of file download is more than 100MB. If the size of the file is around kilobytes that means you have messed up with Oracle License Agreement that you have passed as Header Cookie in your wget request.
--2019-07-06 13:36:45-- https://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.rpm Resolving download.oracle.com (download.oracle.com)… 23.43.160.14 Connecting to download.oracle.com (download.oracle.com)|23.43.160.14|:443… connected. HTTP request sent, awaiting response… 302 Moved Temporarily Location: https://edelivery.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.rpm [following] --2019-07-06 13:36:45-- https://edelivery.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.rpm Resolving edelivery.oracle.com (edelivery.oracle.com)… 2001:559:19:f8a3::366, 2001:559:19:f881::366, 104.106.216.77 Connecting to edelivery.oracle.com (edelivery.oracle.com)|2001:559:19:f8a3::366|:443… connected. HTTP request sent, awaiting response… 302 Moved Temporarily Location: http://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.rpm?AuthParam=1562503038_ceb254a8d1b6fee78bc7cb626aa366ab [following] --2019-07-06 13:36:46-- http://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.rpm?AuthParam=1562503038_ceb254a8d1b6fee78bc7cb626aa366ab Connecting to download.oracle.com (download.oracle.com)|23.43.160.14|:80… connected. HTTP request sent, awaiting response… 301 Moved Permanently Location: https://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.rpm?AuthParam=1562503038_ceb254a8d1b6fee78bc7cb626aa366ab [following] --2019-07-06 13:36:46-- https://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.rpm?AuthParam=1562503038_ceb254a8d1b6fee78bc7cb626aa366ab Connecting to download.oracle.com (download.oracle.com)|23.43.160.14|:443… connected. HTTP request sent, awaiting response… 200 OK Length: 170440632 (163M) [application/x-redhat-package-manager] Saving to: ‘jdk-12.0.1_linux-x64_bin.rpm’ jdk-12.0.1_linux-x64_bin.rpm 100%[==============================================================================================>] 162.54M 2.74MB/s in 56s 2019-07-06 13:37:42 (2.91 MB/s) - ‘jdk-12.0.1_linux-x64_bin.rpm’ saved [170440632/170440632]
Finally using following rpm command with -Uvh switch to ignore the verification of dependencies.
The trick is since you already installed openjdk using yum command, it has already installed the dependencies that are required for Java SE or Oracle JDK. I did not dig to find the Oracle JDK dependencies as pre-requisite for its installation, since I am not fan of non FOSS (Free Open Source Software). If something failed on running java or javac command complaining about a missing dependency, you need to google the error and find the solution.
However, you can install that .rpm local package.
$ sudo rpm -Uvh jdk-12.0.1_linux-x64_bin.rpm
You will get a warning because you have not provided a RPM key
warning: jdk-12.0.1_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY Verifying… ################################# [100%] Preparing… ################################# [100%] Updating / installing… 1:jdk-12.0.1-2000:12.0.1-ga ################################# [100%]
If you check java version, you will see Oracle JDK overrides your openjdk path.
$ 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)
Use jEnv to Switch JDKs
You can refer to Switch JDKs using jEnv page, if you have multiple JDKs installed on your machine, and you need to switch between them fast and without going and set $JAVE_HOME and $PATH environment variables