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-18.0.1.1_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.

cd ~/Downloads
tar xvzf jdk-18.0.1.1_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_home
cp ~/Downloads/jdk-18.0.1.1.jdk/ /Users/<your-user-name>/Library/Java/JavaVirtualMachines/

vim ~/.bash_profile
*** press i on keyboard ***
export JAVA_HOME=/Users/<your-user-name>/Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk/Contents/Home/

*** press esc on keyboard ***
:wq
*** press enter ***
  1. this step would print out the Java home variable which would be /Users/<your-user-name>/Library/Java/JavaVirtualMachines/ on your Mac
  2. cp source destination e.g. cp ~/Downloads/jdk-18.0.1.1.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
  3. vim ~/.zshrc → vim is a command line based text editor for unix systems and 
    1. vim → vim is a command line based text editor for unix systems 
    2. ~/..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.
  4. press ‘i’ → by default vim opens a file in read-only mode, clicking i on the keyboard brings it into editing mode
  5. 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.
  6. Press esc on your keyboard to be out of editing mode in vim
  7. :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 

java --version

and if every thing was done correctly you should see a reference to your new Java version set in your JAVA_HOME.

Conclusion

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. 

Get updates?

If you find any of my posts useful and want to support me, you can buy me a coffee :)

https://www.buymeacoffee.com/bhumansoni

Or you can  buying or even try one of my apps on the App Store. 

https://mydaytodo.com/apps/

In addition the above, have a look at a few of the other posts,
How to create radio buttons using vanilla Javascript
https://mydaytodo.com/vanilla-javascript-create-radio-buttons/

How to build a Javascript frontend for Java Spring Boot backend 
https://mydaytodo.com/java-spring-boot-vanilla-javascript-solution/

Or have a look at some useful Javascript tutorials below
https://mydaytodo.com/category/javascript/
Categories: Command line

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock