Switch the version of java installed by SDKMAN when moving directories

You can use .sdkmanrc to switch versions of java, scala, etc. installed by SDKMAN when moving directories like direnv. It was added relatively recently, so update SDKMAN to the latest version (5.8.3 at the time of writing) to use it.

Generate .sdkmanrc

Run sdk env init in the directory where you want to specify the version.

$ cd sdkenv-test/
$ sdk env init
.sdkmanrc created.

A .sdkmanrc is generated and looks like this:

$ cat .sdkmanrc
# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=8.0.202.j9-adpt

Setting

Specify the version you want to use for the generated .sdkmanrc.

# Enable auto-env through the sdkman_auto_env config
# Add key=value pairs of SDKs to use below
java=13.0.2.j9-adpt

Set to sdkman_auto_env = true in ~ / .sdkman / etc / config. By setting sdkman_auto_env = true, it will switch automatically when you move to a directory like direnv.

Restart the shell.

$ exec $SHELL -l

Execution example

$ cd sdkenv-test/

Using java version 13.0.2.j9-adpt in this shell.

You need to switch manually if sdkman_auto_env = false

If sdkman_auto_env = false is set, it will not switch automatically even if you move to the directory containing .sdkmanrc. You have to run sdk env to switch.

$ cd sdkenv-test/
$ java --version
openjdk 14.0.1 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.1+7)
Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.20.0, JRE 14 Linux amd64-64-Bit Compressed References 20200416_44 (JIT enabled, AOT enabled)
OpenJ9   - 05fa2d361
OMR      - d4365f371
JCL      - 5757187cae based on jdk-14.0.1+7)
$ sdk env

Using java version 13.0.2.j9-adpt in this shell.

Recommended Posts

Switch the version of java installed by SDKMAN when moving directories
[Java version] The story of serialization
Check the version of the JDK installed and the version of the JDK enabled
[Java] Access the signed URL of s3 (signed version 2)
Try the free version of Progate [Java II]
Try the free version of Progate [Java I]
[Java] Check the JDK version of the built war file
Summary of revisions (new era) support by Java version
[Java] When writing the source ... A memorandum of understanding ①
The version of Ruby that was installed by default on the Mac was referenced, not from rbenv
Will programs get faster just by increasing the Java version?
Install by specifying the version of Django in the Docker environment
When using the constructor of Java's Date class, the date advances by 1900.
Traps brought about by the default implementation of the Java 8 interface
Summary of values returned by the Spliterator characteristics method #java
Version control Java with SDKMAN
(Fixed) An error occurs when using Java 8 with the latest version (0.65.0) of Language Support for Java (TM) by Red Hat of VS Code.
I want to judge the necessity of testing by comparing the difference of class files when refactoring Java
Comparison of version strings (Java implementation) when you want to branch the process between two versions
The story of not knowing the behavior of String by passing Java by reference
The point of addiction when performing basic authentication with Java URLConnection
[Java] Appropriate introduction by the people of Tempa Java Part 0 (Code rules)
When using JDBC, NLS parameters are affected by the Java locale.
Let's create a TODO application in Java 5 Switch the display of TODO
Is the version of Elasticsearch you are using compatible with Java 11?
Investigation method when the CPU of the server running java is heavy
Check the version of Cent OS
[Java] Output by FormatStyle of DateTimeFormatter
The origin of Java lambda expressions
Update JAVA to the latest version to 1.8.0_144 (when downloading from the web and updating)
How to find out the Java version of a compiled class file
How to find the total number of pages when paging in Java
Check the domain by checking the MX record of the email address with java
Java / Kotlin: Calculate the quotient by specifying the number of significant digits when it is not divisible by the division (division) of BigDecimal.