Steps to Update Java version on CentOS 6

In this article, we’re going to explain the steps to update Java version on CentOS 6 from 1.7 to 1.8 in Linux. Java is one of the most popular programming languages in the world, and it’s used for a wide range of applications, from building mobile apps to developing enterprise software. As with any software, it’s important to keep Java up-to-date in order to ensure security and performance improvements. In this blog post, we’ll show you how to update Java version on CentOS 6 from 1.7 to 1.8.

You need SSH access to the server and with sudo / root access.

Key features of Java 8

Java 8, released in March 2014, was a major update to the Java programming language. It introduced several new features and improvements that have made Java more powerful, efficient, and user-friendly. Some of the key features of Java 8 are:

  1. Lambda expressions: One of the most significant additions in Java 8, lambda expressions allow developers to write more concise and efficient code by expressing behavior as functions that can be passed around as arguments.
  2. Stream API: Stream API provides a new way to process collections of data in a more declarative and parallelizable manner. It allows developers to perform operations such as filtering, sorting, and mapping on a collection of data in a single statement.
  3. Date and Time API: The new Date and Time API provides a more comprehensive and flexible way to work with dates and times in Java, making it easier to handle time zones, daylight saving time, and other time-related operations.
  4. Default methods: Java 8 introduced the concept of default methods, which allows developers to add new methods to interfaces without breaking existing implementations.
  5. Optional class: The Optional class provides a more elegant way to handle null values in Java, making code more readable and reducing the likelihood of null pointer exceptions.
  6. Nashorn JavaScript engine: Java 8 includes a new JavaScript engine called Nashorn, which allows developers to execute JavaScript code within a Java application.
  7. Parallel arrays: Java 8 introduced the concept of parallel arrays, which allow developers to perform parallel operations on arrays, improving performance on multi-core processors.
  8. Type annotations: Java 8 added support for type annotations, which allows developers to annotate types and type parameters with additional information, improving code readability and maintainability.

Overall, Java 8 was a significant update that brought many new features and improvements to the Java language, making it more powerful, efficient, and user-friendly.

Steps to Update Java Version on CentOS 6

Step 1: First verify the current Java version

[root@linux-AppSer ~]# java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (rhel-2.5.1.2.el6_5-x86_64 u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
[root@linux-AppSer ~]#

The current Java version is 1.7v now upgrade it to 1.8v. Follow the below steps to update the Java version on CentOS 6.

Step 2: Download Java 1.8 Linux 64bit

Some time download URL didn’t work as Oracle updates the URL whenever a new version gets released. Get the URL from the Java official page. and click on the download button or else copy the URL and use it in the below command by just replacing the URL and the command will download the Java package.

[root@linux-AppSer ~]# cd /opt/
[root@linux-AppSer opt]# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u172-b11/a58eab1ec242421181065cdc37240b08/jdk-8u172-linux-x64.tar.gz"

Refer to the below step for 32-bit:

[root@linux-AppSer opt]# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" “http://download.oracle.com/otn-pub/java/jdk/8u172-b11/a58eab1ec242421181065cdc37240b08/jdk-8u172-linux-i586.tar.gz”

Step 3: Extract Java Downloaded tar file

[root@linux-AppSer opt]# tar –xvzf jdk-8u172-linux-x64.tar.gz
[root@linux-AppSer opt]# cd jdk1.8.0_172
[root@linux-AppSer jdk1.8.0_172]#

Steps to Update Java version on CentOS 6

Step 4: Update Java 1.8 version on Amazon Linux

[root@linux-AppSer jdk1.8.0_172]# alternatives --install /usr/bin/java java /opt/jdk1.8.0_172/bin/java 2
[root@linux-AppSer jdk1.8.0_172]# alternatives --config java

There are 3 programs that provide ‘Java’.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
   3           /opt/jdk1.8.0_172/bin/java
Enter to keep the current selection[+], or type selection number: 3
[root@linux-AppSer jdk1.8.0_172]# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_172/bin/javac 2
[root@linux-AppSer jdk1.8.0_172]# alternatives --set javac /opt/jdk1.8.0_172/bin/javac
[root@linux-AppSer jdk1.8.0_172]#

You have successfully updated the JAVA version on CentOS 6 from 1.7v to 1.8v.

Step 5: Confirm Java Version 

[root@linux-AppSer jdk1.8.0_172]# java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
[root@linux-AppSer jdk1.8.0_172]#

Step 6: Set the Java Home path in Linux to make it permanent

vim ~/.bashrc
export JAVA_HOME=/opt/jdk1.8.0_172
export JRE_HOME=/opt/jdk1.8.0_172/jre

Now, you have successfully updated the Java version from 1.7v to 1.8v using a tar file.

How to update Java version 1.7 to 1.8 using rpm file on CentOS 6

Step 1: Check the current Java version

[root@linux-AppSer ~]# java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (rhel-2.5.1.2.el6_5-x86_64 u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
[root@linux-AppSer ~]#

Step 2: Download Java 1.8v for CentOS 6

For 32 bit:

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u172-b11/a58eab1ec242421181065cdc37240b08/jdk-8u172-linux-i586.rpm"

For 64 bit

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u172-b11/a58eab1ec242421181065cdc37240b08/jdk-8u172-linux-x64.rpm"

Step 3: Install downloaded JDK:

[root@linux-AppSer ~] rpm -ivh jdk-8u172-linux-i586.rpm
##(OR)##
[root@linux-AppSer tmp]# rpm -ivh jdk-8u172-linux-x64.rpm
Preparing...                ########################################### [100%]
   1:jdk1.8                 ########################################### [100%]
Unpacking JAR files...
        tools.jar...
        plugin.jar...
        javaws.jar...
        deploy.jar...
        rt.jar...
        jsse.jar...
        charsets.jar...
        localedata.jar...
[root@linux-AppSer tmp]#

JDK is installed and ready to use, by default it is installed in “/usr/java” directory.

Step 4: Verify Java Version

[root@linux-AppSer tmp]# java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
[root@linux-AppSer tmp]#

I hope this guide helps you with the steps to update the Java version on CentOS from 1.7 to 1.8 in Linux using rpm package or tar file.

CentOS 6 Java Update Guide: Best Practices and Common Mistakes to Avoid

Here are the do’s and don’ts, along with common mistakes to avoid when updating the Java version on CentOS 6:

Do:

  1. Backup: Before updating Java on CentOS 6, ensure you have a backup of critical data and configuration files. This precaution will help you revert to the previous state if any issues arise during the update process.
  2. Use Official Repositories: Prefer using the official repositories and package manager like yum to install or update Java. CentOS 6 is an older version, so relying on official sources ensures better maintenance and security.
  3. Update CentOS: Before installing the new Java version, make sure your CentOS 6 system is up-to-date with the latest patches and updates. This helps ensure compatibility and may fix issues that could arise during the update.
  4. Verify Dependencies: Check for any dependencies required by your software to run on the updated Java version. Ensuring all dependencies are met avoids potential problems with applications not functioning correctly.
  5. Test in Staging: If possible, test the Java update on a staging server or environment before applying it to the production server. Testing helps identify any potential issues before they affect your live systems.

Don’t:

  1. Avoid Manual Installation: Unless absolutely necessary, avoid manually installing Java from tarballs or ZIP files. Using the package manager is recommended to maintain consistency and simplify future updates.
  2. Don’t Remove Current Version First: Avoid removing the current Java version before verifying that the new version works correctly. Removing the existing version first can leave your system without a working Java runtime if the new version encounters issues.
  3. Don’t Mix Package Managers: Stick to using the yum package manager for CentOS 6. Mixing it with other package managers or manual installations can lead to conflicts and dependency issues.
  4. Skipping Updates: Regularly update your Java version on CentOS 6. Skipping updates can lead to security vulnerabilities and compatibility problems with newer software.

Common Mistakes:

  1. Incompatible Java Version: CentOS 6 might have limitations on the Java version it can support. Installing a Java version that is not compatible with CentOS 6 can cause unexpected errors.
  2. Missing Dependencies: Failing to install all the necessary dependencies for the new Java version can result in applications not running correctly or crashing.
  3. Incomplete Installation: Sometimes, an update might not complete successfully due to interrupted internet connections or other issues. Always verify that the update process is finished without errors.
  4. Neglecting Compatibility Testing: Some applications running on CentOS 6 may not be compatible with the latest Java version. Test your applications thoroughly after the update to ensure they function as expected.

By following these do’s and don’ts and avoiding common mistakes, you can update the Java version on CentOS 6 smoothly and minimize the risk of encountering problems during the process.

Linux Tips/Tricks

Command to check which Linux version 

[root@linux-AppSer tmp]# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m
[root@linux-AppSer tmp]# cat /etc/*release
CentOS release 6.6 (Final)
LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
CentOS release 6.6 (Final)
CentOS release 6.6 (Final)
[root@linux-AppSer tmp]#

Command to check Linux Arch

[root@linux-AppSer tmp]# uname -a
Linux linux-AppSer 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Updating Java on CentOS 6 from 1.7 to 1.8 is a straightforward process, but it’s important to follow these steps carefully to ensure that everything is done correctly. By keeping Java up-to-date, you’ll ensure that your system is secure and running at its best.

See also:

Steps to Upgrade Java 8 to Java 11 on CentOS 7

How to Upgrade Java 11 To Java 16 on Rocky Linux or AlmaLinux

How to Upgrade Java 8 To Java 11 on Rocky Linux or AlmaLinux

How to Install Java 8 on Rocky Linux 8 / CentOS 8 / RHEL 8: A Step-by-Step Guide

How to Upgrade Java 8 to Java 11 on Ubuntu 20

How to Install Java 8 on Ubuntu 20

List of monitoring tools 

Linux Blogs

AWS Cloud Blogs

Database Blogs

DevOps Blogs

Interview Questions & Answers

Docker Blogs

Google Cloud Blogs