###### tags: `java` `jabba` Install multiple version/distribution of Java === For Ubuntu Linux, macOS, Windows --- - Use `jabba`: https://github.com/shyiko/jabba - Use installation script described on the README to install it :::danger - The prefered way to install `jabba` is via **the installation script** - This will make sure all the features is working out of the box - Because there are knowing issues that if you install `jabba` via package manager (e.g. `homebrew`, `scoop`, etc), some feature will not working unless you manually tweaks your shell - https://github.com/shyiko/jabba/issues/138 - https://github.com/shyiko/jabba/issues/707 ::: - Switch the global version of java - on Ubuntu Liunx, use `update-alternatives` command as following ```bash # select jdk before using `update-alternatives` command $ jabba use adoptopenjdk@1.16.0-1 $ sudo update-alternatives --install /usr/bin/java java ${JAVA_HOME%*/}/bin/java 20000 $ sudo update-alternatives --install /usr/bin/javac javac ${JAVA_HOME%*/}/bin/javac 20000 ``` - on macOS, just set the default alias, and you are good to go! ```bash $ jabba alias default adopt-openj9@1.16.0-1 ``` - on Windows, run the following powershell script as administrator ```powershell # select jdk jabba use adopt-openj9@1.16.0-1 # modify global PATH & JAVA_HOME environment variable $envRegKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey('SYSTEM\CurrentControlSet\Control\Session Manager\Environment', $true) $envPath = $envRegKey.GetValue('Path', $null, "DoNotExpandEnvironmentNames").replace('%JAVA_HOME%\bin;', '') [Environment]::SetEnvironmentVariable('JAVA_HOME', "$(jabba which $(jabba current))", 'Machine') [Environment]::SetEnvironmentVariable('PATH', "%JAVA_HOME%\bin;$envPath", 'Machine') ``` For Arch Linux --- - Just install JDK from standard arch repository or AUR - Use `archlinux-java` helper script to switch the global version of Java - For more details: https://wiki.archlinux.org/title/Java