Switch JDK Versions in Linux

Switching JDK Versions

Switching JDK Versions

If you want to switch between different JDK major versions that are available

Try below command, choose option

switch.sh
$/> alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.el7_9.x86_64/jre/bin/java)

Enter to keep the current selection[+], or type selection number: 1
  • If you want to install new version

new.sh
yum install java-11-openjdk-devel
Loaded plugins: tsflags, versionlock
Resolving Dependencies
--> Running transaction check
---> Package java-11-openjdk-devel.x86_64 1:11.0.19.0.7-1.0.1.el7_9 will be installed
--> Processing Dependency: java-11-openjdk(x86-64) = 1:11.0.19.0.7-1.0.1.el7_9 for package: 1:java-11-openjdk-devel-11.0.19.0.7-1.0.1.el7_9.x86_64
--> Running transaction check
---> Package java-11-openjdk.x86_64 1:11.0.19.0.7-1.0.1.el7_9 will be installed
--> Processing Dependency: java-11-openjdk-headless(x86-64) = 1:11.0.19.0.7-1.0.1.el7_9 for package: 1:java-11-openjdk-11.0.19.0.7-1.0.1.el7_9.x86_64
--> Running transaction check
---> Package java-11-openjdk-headless.x86_64 1:11.0.19.0.7-1.0.1.el7_9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================
 Package                                           Arch                            Version                                               Repository                                                    Size
============================================================================================================================================================================================================
Installing:
 java-11-openjdk-devel                             x86_64                          1:11.0.19.0.7-1.0.1.el7_9                             io-ol7-latest-yum-local-20230501.01                          3.4 M
Installing for dependencies:
 java-11-openjdk                                   x86_64                          1:11.0.19.0.7-1.0.1.el7_9                             io-ol7-latest-yum-local-20230501.01                          239 k
 java-11-openjdk-headless                          x86_64                          1:11.0.19.0.7-1.0.1.el7_9                             io-ol7-latest-yum-local-20230501.01                           39 M

Transaction Summary
============================================================================================================================================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 43 M
Installed size: 170 M
Is this ok [y/d/N]:
Note
java-11-openjdk-devel requires java-11-openjdk and java-11-openjdk-headless

Dependencies in the order

  • java-11-openjdk-devel : is development environment

  • java-11-openjdk : runtime environment

  • java-11-openjdk-headless : non gui libraries

Switch Between Minor Versions from Local YUM Repository

If Linux Distribution comes with different JDK Versions. verify all possible options with below command.

available.sh
sudo yum --showduplicates list java-1.8.0-openjdk

java-1.8.0-openjdk.i686                                                              1:1.8.0.332.b09-1.el7_9                                                            io-ol7-latest-yum-local-20230501.01
java-1.8.0-openjdk.x86_64                                                            1:1.8.0.332.b09-1.el7_9                                                            io-ol7-latest-yum-local-20230501.01
java-1.8.0-openjdk.i686                                                              1:1.8.0.342.b07-1.el7_9                                                            io-ol7-latest-yum-local-20230501.01
java-1.8.0-openjdk.x86_64                                                            1:1.8.0.342.b07-1.el7_9                                                            io-ol7-latest-yum-local-20230501.01
java-1.8.0-openjdk.i686                                                              1:1.8.0.345.b01-1.el7_9                                                            io-ol7-latest-yum-local-20230501.01
java-1.8.0-openjdk.x86_64                                                            1:1.8.0.345.b01-1.el7_9                                                            io-ol7-latest-yum-local-20230501.01
java-1.8.0-openjdk.i686                                                              1:1.8.0.352.b08-2.el7_9                                                            io-ol7-latest-yum-local-20230501.01
java-1.8.0-openjdk.x86_64                                                            1:1.8.0.352.b08-2.el7_9                                                            io-ol7-latest-yum-local-20230501.01
java-1.8.0-openjdk.i686                                                              1:1.8.0.362.b08-1.el7_9                                                            io-ol7-latest-yum-local-20230501.01
java-1.8.0-openjdk.x86_64                                                            1:1.8.0.362.b08-1.el7_9                                                            io-ol7-latest-yum-local-20230501.01
java-1.8.0-openjdk.i686                                                              1:1.8.0.372.b07-1.el7_9                                                            io-ol7-latest-yum-local-20230501.01
java-1.8.0-openjdk.x86_64                                                            1:1.8.0.372.b07-1.el7_9                                                            io-ol7-latest-yum-local-20230501.01

Downgrading

If you want lower minor version of JDK than current version , run below command

downgrade.sh
yum downgrade java-1.8.0-openjdk-headless-1.8.0.362.b08-1.el7_9 java-1.8.0-openjdk-1.8.0.362.b08-1.el7_9 java-1.8.0-openjdk-devel-1.8.0.362.b08-1.el7_9
Upgrade

if you want higher minor version of JDK than current version, run below command

upgrade.sh
java-1.8.0-openjdk-headless-1.8.0.372.b07-1.el7_9 java-1.8.0-openjdk-1.8.0.372.b07-1.el7_9 java-1.8.0-openjdk-devel-1.8.0.372.b07-1.el7_9

Comments

Popular posts from this blog

IBM Datapower GatewayScript

Spring boot Kafka Integration

Spring boot SOAP Web Service Performance