How to switch Java in the OpenJDK era on Mac

Install Java using SDKMAN! and switch with it.

[Addition] Install Bash 4 series or more

When using SKDMAN! With Bash on Mac, 4 or more Bash was required, so install it in a timely manner.

$ brew install bash
$ sudo vim /etc/shells
At the end/usr/local/bin/Add bash
$ chsh -s /usr/local/bin/bash

Finally restart the terminal

* When bash does not switch

If / usr / local / bin / bash doesn't come first in the result below,

$ which -a bash
/bin/bash
/usr/local/bin/bash

Check / etc / paths and move / usr / lobal / bin before / bin.

/etc/paths


/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

Also, if the chsh execution result is chsh: no changes made, change it from the Mac system environment settings. (It may have changed when confirmed)

Installing SDKMAN!

$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"

Java installation

If you just want to install it, run sdk install java to get the latest OpenJDK.

$ sdk install java
==== BROADCAST =================================================================
* 2019-04-02: Vertx 3.7.0 released on SDKMAN! #vertx
* 2019-03-28: Micronaut 1.1.0.RC2 released on SDKMAN! #micronautfw
* 2019-03-28: Gradle 5.3.1 released on SDKMAN! #gradle
================================================================================

Downloading: java 11.0.2-open

In progress...

######################################################################## 100.0%

Repackaging Java 11.0.2-open...

Done repackaging...
Cleaning up residual files...

Installing: java 11.0.2-open
Done installing!


Setting java 11.0.2-open as default.

Set JAVA_HOME if necessary.

.bashrc


export JAVA_HOME=$HOME/.sdkman/candidates/java/current
export PATH=$JAVA_HOME/bin:$PATH

I want to select a version

1. Search

Find the version you want to install and install Java

$ sdk list java
================================================================================
Available Java Versions
================================================================================
     13.ea.14-open       8.0.202-amzn                                           
     12.0.0-zulu         8.0.202.j9-adpt                                        
     12.0.0-open         8.0.202.hs-adpt                                        
     11.0.2-sapmchn      8.0.202-zulufx                                         
     11.0.2-zulu         8.0.201-oracle                                         
 > * 11.0.2-open         7.0.181-zulu                                           
     11.0.2-amzn         1.0.0-rc-14-grl                                        
     11.0.2.j9-adpt      1.0.0-rc-13-grl                                        
     11.0.2.hs-adpt      1.0.0-rc-12-grl                                        
     11.0.2-zulufx       1.0.0-rc-11-grl                                        
     10.0.2-zulu         1.0.0-rc-10-grl                                        
     10.0.2-open         1.0.0-rc-9-grl                                         
     9.0.7-zulu          1.0.0-rc-8-grl                                         
     9.0.4-open                                                                 
     8.0.202-zulu                                                               

================================================================================
+ - local version
* - installed
> - currently in use
================================================================================

2. Install

$ sdk install java 8.0.202-amzn

3. Set the version

Change only specific terminals

$ sdk use java 8.0.202-amzn

Change the default of the JDK to use

$ sdk default java 8.0.202-amzn

Recommended Posts

How to switch Java in the OpenJDK era on Mac
How to switch Java versions on Mac
How to switch Java version with direnv in terminal on Mac
How to check Java installed on Mac
How to get the date in java
[Java] Memo on how to write the source
How to uninstall Java 8 (Mac)
[Java] How to omit the private constructor in Lombok
Notes on how to use regular expressions in Java
How to get the class name / method name running in Java
[Java] How to update Java on Windows
How to learn JAVA in 7 days
How to dynamically switch JDK when building Java in Gradle
How to use classes in Java?
How to name variables in Java
How to derive the last day of the month in Java
How to concatenate strings in java
How to uninstall if you have updated to Java 9 on your Mac
How to automatically operate a screen created in Java on Windows
How to solve the unknown error when using slf4j in Java
How to get the length of an audio file in java
How to get JDK 11 on your mac in a comfortable way
How to increment the value of Map in one line in Java
How to implement date calculation in Java
Multilingual Locale in Java How to use Locale
[Java] How to use the File class
Java reference to understand in the figure
[Java] How to use the hasNext function
[Java] How to use the HashMap class
How to install Eclipse (Photon) on Mac
I tried the new era in Java
How to do base conversion in Java
[Java] How to use the toString () method
Studying how to use the constructor (java)
[Java] How to set the Date time to 00:00:00
[Java] How to get the current directory
How to implement coding conventions in Java
How to embed Janus Graph in Java
How to install the legacy version [Java]
[Processing × Java] How to use the function
[Java] How to use the Calendar class
How to switch between multiple Java versions
[Java] How to retrieve the parameters passed from html on the server side
[Swing] How to display an arbitrary name on the menu bar on Mac
How to find the total number of pages when paging in Java
How to get the value after "_" in Windows batch like Java -version
How to solve the local environment construction of Ruby on Rails (MAC)!
How to debug the processing in the Ruby on Rails model only on the console
How to create your own annotation in Java and get the value
How to check the logs in the Docker container
[Java] How to use Thread.sleep to pause the program
How to display a web page in Java
How to add sound in the app (swift)
How to get Class from Element in Java
How to hide null fields in response in Java
[Java] How to switch from open jdk to oracle jdk
How to use the replace () method (Java Silver)
[Java] How to substitute Model Mapper in Jackson
How to solve an Expression Problem in Java
[Java] How to get the redirected final URL
[Ruby on Rails] How to install Bootstrap in Rails