This is a manual process but the aim of this document is to provide an easy to follow guide of how to setup Java 18 on your Mac.
Setup Java 18 on your mac
Download Java 18
Download Java 18 from the following location https://www.oracle.com/java/technologies/javase/jdk18-archive-downloads.html. Scroll down the web page and download a file called jdk-188.8.131.52_macos-aarch64_bin.tar.gz which is the latest version at the time of writing this document.
Untar (unzip) the archive downloaded
By default the above step will download the file to the downloads folder. Open your terminal, navigate to the downloads folder and unzip the file with the tar command as shown bellow.
tar xvzf jdk-184.108.40.206_macos-aarch64_bin.tar.gz
The above step will extract the contents of the file to a folder called jdk-11.0.15.jdk.
Locate Java on your Mac and copy JDK
In the step above you downloaded JDK 18 library, now it is time to copy it to a location from where you can call it. To do the above, execute the following steps from the terminal
- Find where Java is installed on your Mac
- Copy the extracted JDK directory to it
- Modify the terminal profile
- Set and export a new JAVA_HOME variable
/usr/libexec/java_homecp ~/Downloads/jdk-220.127.116.11.jdk/ /Users/<your-user-name>/Library/Java/JavaVirtualMachines/
*** press i on keyboard ***export JAVA_HOME=/Users/<your-user-name>/Library/Java/JavaVirtualMachines/jdk-18.104.22.168.jdk/Contents/Home/
*** press esc on keyboard ***
*** press enter ***
- this step would print out the Java home variable which would be /Users/<your-user-name>/Library/Java/JavaVirtualMachines/ on your Mac
- cp source destination e.g. cp ~/Downloads/
jdk-22.214.171.124.jdk/ /Users/<your-user-name>/Library/Java/JavaVirtualMachines/ is a unix command to copy files alternatively you can also use mv with the same syntax to move the file
- vim ~/.zshrc → vim is a command line based text editor for unix systems and
- vim → vim is a command line based text editor for unix systems
.bash_profile → when you launch a terminal on your mac it will execute a profile associated with it. The profile depends on the type of terminal configured to launch on your mac. These terminals or shells use different profiles. In the example above, you are configuring a
.bash_profile which will work with a bash shell (terminal). Alternatively Macs can also have a z-shell configured to launch, hence the profile associated with it would be a .zshrc file on your Home directory. In a nutshell the commands in your .bash_profile file are activated every time you launch your terminal.
- press ‘i’ → by default vim opens a file in read-only mode, clicking i on the keyboard brings it into editing mode
- In the next step you are exporting (setting) a new JAVA_HOME, so every time you launch your terminal, it knows where is JAVA_HOME located.
- Press esc on your keyboard to be out of editing mode in vim
- :wq → this indicates you want to write your changes and quit vim
Check your Java version
After you have done all of the above, launch a new terminal
and if every thing was done correctly you should see a reference to your new Java version set in your JAVA_HOME.
The concepts presented here on editing bash profile (.bash_profile) by setting up shortcuts and exporting new path variables are general and can be applied to setting up applications on your mac.