{"id":321,"date":"2022-09-27T20:47:08","date_gmt":"2022-09-27T20:47:08","guid":{"rendered":"https:\/\/techtutelage.net\/?p=321"},"modified":"2024-02-13T19:28:51","modified_gmt":"2024-02-13T19:28:51","slug":"install-uninstall-and-change-default-java-jdk-version-on-macos","status":"publish","type":"post","link":"https:\/\/techtutelage.net\/?p=321","title":{"rendered":"Install and set default Java JDK version on macOS"},"content":{"rendered":"\n<iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/2VxsPtZVfPE\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n\n\n\n<h2 class=\"wp-block-heading\">Install the latest version of Java JDK<\/h2>\n\n\n\n<p>To install the latest version of JDK on macOS follow the steps outlined below:<\/p>\n\n\n\n<p>First, check to see if you already have Java installed on your system. To do so, open the terminal window of your mac by clicking the Launchpad icon in the Dock, then type Terminal in the search field, and click on Terminal. Once you have the terminal open run the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>java --version<\/code><\/pre>\n\n\n\n<p>If Java is not installed on your system, you will see a message that looks something like this.<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>The operation couldn\u2019t be completed. Unable to locate a Java Runtime.\nPlease visit http:\/\/www.java.com for information on installing Java.<\/code><\/pre>\n\n\n\n<p>Otherwise you will see message similar to the message below, in this case we can see that the system has Java 17 installed.<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>java 17.0.4.1 2022-08-18 LTS\nJava(TM) SE Runtime Environment (build 17.0.4.1+1-LTS-2)\nJava HotSpot(TM) 64-Bit Server VM (build 17.0.4.1+1-LTS-2, mixed mode, sharing)<\/code><\/pre>\n\n\n\n<p>To download and install the latest version of Java, in your browser go to <a rel=\"noreferrer noopener\" href=\"https:\/\/www.oracle.com\/java\/technologies\/downloads\/\" target=\"_blank\">Java Downloads Oracle<\/a>. Select the latest version of Java (currently 19), the operating system (macOS), and the architecture of your Mac. If you are on Intel based Mac select x64 DMG Installer, if you are on Apple Silicon Select Arm 64 DMG Installer.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"566\" src=\"https:\/\/techtutelage.net\/wp-content\/uploads\/2023\/03\/Screen-Shot-2023-03-11-at-5.33.39-PM-1024x566.png\" alt=\"\" class=\"wp-image-327\" srcset=\"https:\/\/techtutelage.net\/wp-content\/uploads\/2023\/03\/Screen-Shot-2023-03-11-at-5.33.39-PM-1024x566.png 1024w, https:\/\/techtutelage.net\/wp-content\/uploads\/2023\/03\/Screen-Shot-2023-03-11-at-5.33.39-PM-300x166.png 300w, https:\/\/techtutelage.net\/wp-content\/uploads\/2023\/03\/Screen-Shot-2023-03-11-at-5.33.39-PM-768x425.png 768w, https:\/\/techtutelage.net\/wp-content\/uploads\/2023\/03\/Screen-Shot-2023-03-11-at-5.33.39-PM-1536x849.png 1536w, https:\/\/techtutelage.net\/wp-content\/uploads\/2023\/03\/Screen-Shot-2023-03-11-at-5.33.39-PM-2048x1132.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Once you have the Installer .dmg file downloaded, double-click on it to open then double click on the JDK package to start the installation. In the installation window click&nbsp;<strong>Continue<\/strong> and&nbsp;<strong>Install<\/strong>. A window will appear and it will ask you for user name and password. Enter the Administrator user name and password and click&nbsp;<strong>Install Software<\/strong>. Once the software is installed a confirmation window will display, click on Cancel. You will be prompted to delete the installer, at this point you can go ahead and delete it if you want to save disk space.<\/p>\n\n\n\n<p>Go back to the terminal window  and run<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>java --version<\/code><\/pre>\n\n\n\n<p>This time the result should show that you have installed the latest version of Java.<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>java 19.0.2 2023-01-17\nJava(TM) SE Runtime Environment (build 19.0.2+7-44)\nJava HotSpot(TM) 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Change the default version of Java<\/h2>\n\n\n\n<p>First get a list of all the installed Java versions on you Mac by running the following command<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>\/usr\/libexec\/java_home -V<\/code><\/pre>\n\n\n\n<p>The result should look similar to this<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>Matching Java Virtual Machines (2):\n    19.0.2 (x86_64) \"Oracle Corporation\" - \"Java SE 19.0.2\" \/Library\/Java\/JavaVirtualMachines\/jdk-19.jdk\/Contents\/Home\n    17.0.6 (x86_64) \"Oracle Corporation\" - \"Java SE 17.0.6\" \/Library\/Java\/JavaVirtualMachines\/jdk-17.jdk\/Contents\/Home<\/code><\/pre>\n\n\n\n<p>To temporary switch the default Java version to 17 (only for the current terminal session). Run the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>export JAVA_HOME='\/usr\/libexec\/java_home -v 17'<\/code><\/pre>\n\n\n\n<p>To make the change permanent run<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>export JAVA_HOME=$(\/usr\/libexec\/java_home -v 17)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Remove\/Uninstall Java from Mac<\/h2>\n\n\n\n<p><strong>Note: Never uninstall Java by removing the Java tools from \/usr\/bin <\/strong><\/p>\n\n\n\n<p>First, open your Terminal window and run the following commands<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>cd \/Library\/Java\/JavaVirtualMachines\nls -l \/Library\/Java\/JavaVirtualMachines<\/code><\/pre>\n\n\n\n<p>This will show you the versions of Java currently installed on your Mac. <\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>drwxr-xr-x  3 root  wheel  96 Mar 12 01:56 jdk-17.jdk\ndrwxr-xr-x  3 root  wheel  96 Mar 12 21:39 jdk-19.jdk<\/code><\/pre>\n\n\n\n<p>To uninstall Java, all you need to do is remove the directory for the version you want uninstalled by executing the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-black-background-color has-text-color has-background\"><code>sudo rm -rf jdk-19.jd<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Install the latest version of Java JDK To install the latest version of JDK on macOS follow the steps outlined below: First, check to see if you already have Java installed on your system. To do so, open the terminal window of your mac by clicking the Launchpad icon in the Dock, then type Terminal [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,1],"tags":[],"class_list":["post-321","post","type-post","status-publish","format-standard","hentry","category-tutorials","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/posts\/321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/techtutelage.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=321"}],"version-history":[{"count":10,"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions"}],"predecessor-version":[{"id":391,"href":"https:\/\/techtutelage.net\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions\/391"}],"wp:attachment":[{"href":"https:\/\/techtutelage.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtutelage.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtutelage.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}