Skip to main content

Java Development Environment

Install

Install Java using Coursier. If you haven't installed Coursier yet, install it first. (Coursier Installation)

Install Java 17

To install Java 17 (Adoptium),

cs java --jvm adoptium:17 

Install Java 11

To install Java 11 (AdoptOpenJDK),

cs java --jvm adoptium:11

Install Java 8

To install Java 8 (AdoptOpenJDK),

cs java --jvm adopt:8

It's often convenient to create symbolic links to JDK.

The folders of the JDK installed by Coursier have the version info in it. So if you link them to IDE, you probably need to re-link the new folder whenever you upgrade JDKs. To avoid this hassle, you can use symbolic links to the JDKs instead of the actual folder paths.

List Installed JDKs

To simplify symlink creation, you can use jdk-sym-link.

bash -c "$(curl -fsSL https://raw.githubusercontent.com/Kevin-Lee/jdk-sym-link/main/.scripts/install.sh)" 

The one above should work for both Intel and M1 Macs but if it doesn't. try the JVM version below.

bash -c "$(curl -fsSL https://raw.githubusercontent.com/Kevin-Lee/jdk-sym-link/main/.scripts/install-jvm.sh)" 

Once installation is done, run the following commands to see all installed JDKs.

jdkslink list 

The expected result might be something like this.


$ ls -l /Library/Java/JavaVirtualMachines

total 0
drwxr-xr-x 4 root wheel 128 27 Sep 00:53 adoptopenjdk-8.jdk
drwxr-xr-x 3 root wheel 96 25 Mar 2019 jdk1.8.0_202.jdk
lrwxr-xr-x 1 root wheel 59 17 Oct 18:43 jdk11 -> /Users/USERNAME/Library/Caches/Coursier/jvm/adopt@1.11.0-10
lrwxr-xr-x 1 root wheel 59 14 Oct 00:02 jdk8 -> /Users/USERNAME/Library/Caches/Coursier/jvm/adopt@1.8.0-292


$ ls -l /Users/USERNAME/Library/Caches/Coursier/jvm

total 0
drwxr-xr-x 3 USERNAME staff 96 17 Oct 18:43 adopt@1.11.0-10
drwxr-xr-x 3 USERNAME staff 96 26 Sep 16:55 adopt@1.11.0-11
drwxr-xr-x 3 USERNAME staff 96 26 Sep 17:52 adopt@1.8.0-292
drwxr-xr-x 3 USERNAME staff 96 21 Mar 2021 graalvm-java11@20.2.0
drwxr-xr-x 3 USERNAME staff 96 7 Jul 00:54 graalvm-java11@21.1.0
drwxr-xr-x 15 USERNAME staff 480 26 Sep 21:01 zulu@1.11.0-10
jdkslink slink 11

The expected result might be like


Version(s) found:
[0] adopt@1.11.0-10
[1] zulu@1.11.0-10
[2] adopt@1.11.0-11
[c] Cancel

2

You chose 'adopt@1.11.0-11'.
It will create a symbolic link to 'adopt@1.11.0-11' (i.e. jdk11 -> adopt@1.11.0-11)
and may ask you to enter your password.

Would you like to proceed? (y / n)
y

/Library/Java/JavaVirtualMachines/jdk11: It is found so will be removed and recreated.

/Library/Java/JavaVirtualMachines $ sudo rm jdk11
/Library/Java/JavaVirtualMachines $ sudo ln -s adopt@1.11.0-11 jdk11


Done!

# Before
--------------------------------------
total 0
drwxr-xr-x 4 root wheel 128 27 Sep 00:53 adoptopenjdk-8.jdk
drwxr-xr-x 3 root wheel 96 25 Mar 2019 jdk1.8.0_202.jdk
lrwxr-xr-x 1 root wheel 59 17 Oct 18:43 jdk11 -> /Users/USERNAME/Library/Caches/Coursier/jvm/adopt@1.11.0-10
lrwxr-xr-x 1 root wheel 59 14 Oct 00:02 jdk8 -> /Users/USERNAME/Library/Caches/Coursier/jvm/adopt@1.8.0-292

======================================

# After
--------------------------------------
total 0
drwxr-xr-x 4 root wheel 128 27 Sep 00:53 adoptopenjdk-8.jdk
drwxr-xr-x 3 root wheel 96 25 Mar 2019 jdk1.8.0_202.jdk
lrwxr-xr-x 1 root wheel 59 17 Oct 18:45 jdk11 -> /Users/USERNAME/Library/Caches/Coursier/jvm/adopt@1.11.0-11
lrwxr-xr-x 1 root wheel 59 14 Oct 00:02 jdk8 -> /Users/USERNAME/Library/Caches/Coursier/jvm/adopt@1.8.0-292

======================================

Now, let's create the symbolic link for Java 8 as well,

jdkslink slink 8

jEnv

Install

brew install jenv 
{ echo $PATH | grep -q "$HOME/.jenv/bin" ; } || { echo 'if type jenv >/dev/null 2>&1; then
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
else
echo "No jenv found. Consider using it. https://github.com/jenv/jenv"
fi' >> ~/.zshrc ; }

Once installed, if there is no ~/.jenv/versions, adding JDK to jenv may fail, so create the folder first with the following command.

mkdir -p  ~/.jenv/versions 

Add JDK

Add JDK 11

jenv add /Library/Java/JavaVirtualMachines/jdk11/Contents/Home 

Add JDK 8

jenv add /Library/Java/JavaVirtualMachines/jdk8/Contents/Home 

Add JDK 17

jenv add /Library/Java/JavaVirtualMachines/jdk17/Contents/Home 

Check all jenv linked versions,

jenv versions 

e.g.)

* system (set by /Users/USERNAME/.jenv/version)
1.8
1.8.0.222
11
11.0
11.0.11
openjdk64-1.8.0.222
openjdk64-11.0.11

Set Global Java Version

To set the global Java version to 11,

jenv global 11

To check,

jenv global
11

jenv versions may show

jenv versions 
  system
1.8
1.8.0.222
* 11 (set by /Users/USERNAME/.jenv/version)
11.0
11.0.11
openjdk64-1.8.0.222
openjdk64-11.0.11

TBD