[LINUX] [Java] How to switch between multiple versions of Java

Introduction

There is also a method using multiple versions of Java by switching Java, such as method using jenv, but here the method using orthodox alternatives I'd like to introduce_______

For example, I think it will be useful in the following scenes, so it may be useful to remember just the command name alternatives.

What is the alternatives command?

alternatives are commands that come standard with CentOS.

If you look up alternatives with the man command, it says "maintain symbolic links determining default commands". It's hard to understand in English, but it's an excellent command that says, "You can use symbolic links to switch between software with similar functions and software with different versions."

In other words, it can be applied not only to Java but also to various commands **.

testing environment

[root@akagi ~]# 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)

Advance preparation

Installation of new Java (OpenJDK)

  1. Download Java12 tar.gz from OpenJDK Site.
  2. Place and extract tar.gz under an appropriate directory (* here / usr / local) to complete the installation.
[root@akagi ~]# cd /usr/local/
[root@akagi local]# tar zxvf openjdk-12.0.1_linux-x64_bin.tar.gz 
[root@akagi local]# ls | grep jdk
jdk-12.0.1
openjdk-12.0.1_linux-x64_bin.tar.gz

Switching Java with the alternatives command

Check the current status

[root@akagi local]# alternatives --config java

There is one program'java'To provide.

Select command
-----------------------------------------------
*+ 1           /usr/java/jdk-12.0.1/bin/java

Press Enter to select the current[+]Or enter the selection number:

Command registration-Switching the JVM to use

[root@akagi local]# alternatives --install /usr/bin/java java /usr/local/jdk-12.0.1/bin/java 2
[root@akagi local]# alternatives --config java

There are 2 programs'java'To provide.

Select command
-----------------------------------------------
*+ 1           /usr/java/jdk-12.0.1/bin/java
   2           /usr/local/jdk-12.0.1/bin/java

Press Enter to select the current[+]Or enter the selection number:2

Check the status after setting

[root@akagi local]# alternatives --config java

There are 2 programs'java'To provide.

Select command
-----------------------------------------------
*  1           /usr/java/jdk-12.0.1/bin/java
 + 2           /usr/local/jdk-12.0.1/bin/java

Press Enter to select the current[+]Or enter the selection number:
[root@akagi local]# java -version
openjdk version "12.0.1" 2019-04-16
OpenJDK Runtime Environment (build 12.0.1+12)
OpenJDK 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)

Other

Reference URL

Recommended Posts

[Java] How to switch between multiple versions of Java
Switch versions when multiple versions of java are included on Linux
How to switch python versions in cloud9
How to handle multiple versions of CUDA in the same environment
How to switch between Linux and Mac shells
How to build an environment for using multiple versions of Python on Mac
How to display multiple images of galaxies in tiles
Summary of how to share state with multiple functions
How to display a list of installable versions with pyenv
Summary of how to use pandas.DataFrame.loc
Summary of how to use pyenv-virtualenv
Switch between multiple models with M5StickV
How to implement Java code in the background of RedHat (LinuxONE)
[Python] Summary of how to use pandas
How to title multiple figures with matplotlib
How to speed up instantiation of BeautifulSoup
How to change multiple columns of csv in Pandas (Unixtime-> Japan Time)
How to get rid of long comprehensions
How to check the version of Django
How to install CatBoost [as of January 2020]
How to calculate Use% of df command
[Python2.7] Summary of how to use unittest
How to switch mouse operations on CentOS
Start multiple containers in VS Code's Remote Container to switch between tasks
Jupyter Notebook Basics of how to use
[Bash] Redirection of multiple lines to multiple files
Summary of how to use Python list
[Python2.7] Summary of how to use subprocess
Summary of how to write AWS Lambda
[Question] How to use plot_surface of python
How to assign multiple values to the Matplotlib colorbar
How to calculate the volatility of a brand
How to use folium (visualization of location information)
A simple example of how to use ArgumentParser
How to find the area of the Voronoi diagram
How to make Spigot plugin (for Java beginners)
How to keep track of work in Powershell
Summary of how to import files in Python 3
Use multiple versions of python environment with pyenv
Not much mention of how to use Pickle
Summary of how to use MNIST in Python
How to implement "named_scope" of RubyOnRails with Django
How to build Java environment on Ubuntu (Linux)
How to return multiple indexes with index method
Switch Python versions
How to install and use pyenv, what to do if you can't switch python versions
How to know the port number of the xinetd service
How to get multiple model objects randomly in Django
How to get the number of digits in Python
I tried to summarize how to use matplotlib of python
How to write string concatenation in multiple lines in Python
How to measure processing time in Python or Java
Memo of how to use properly when combining pandas.DataFrame
How to visualize the decision tree model of scikit-learn
How to write a list / dictionary type of Python3
How to use Python Kivy ① ~ Basics of Kv Language ~
Link the mouse to the gyro of the Nintendo Switch Procon
How to output CSV of multi-line header with pandas
How to check the Java version used by Maven
[Blender] How to dynamically set the selection of EnumProperty
How to infer MAP estimate of HMM with PyStruct