How to Install Java on Mac | Install Java JDK on macOS (2024)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this video I'm going to show you how you can download and install Java jdk on your Mac operating system in addition I'm also going to show you how you can set the Java home in your Mac operating system and also I'm going to show you how you can run a Java file once you have installed Java on your Mac operating system so let's start with the download of java so for that open your favorite browser and search for download Oracle Java on Mac and the first link which will appear here will be from oracle.com SL Java SL Technologies SL download I'm going to click on this link maybe I will also put this link in the description of this video so you can directly come to this website now at the time of making this video you can see Java 21 and Java 177 are available now what we are going to do do is we are going to download the version Java 21 now when you scroll down a little you will see three sections for Linux Mac OS and windows we are going to click on the Mac version and then you will see uh different variants which you can download we are interested in downloading the DMG installer but here there are two variants of DMG installer also so if you are using M1 or M2 Mech then you need to select this one which is arm 64 DMG installer if you are using Intel backed Mac operating system then you need to choose the last uh one which is x64 DMG installer I am having the M2 Chip on my Mac operating system so I'm going to choose CH the second option which is arm 64 DMG installer so I'm going to click on this link which is for the download of this DMG file you can see the download of this G DMG file has been started so it's not going to take much time to download just wait for the download to complete and once the download is complete you can see this DMG file is downloaded so I can directly click on this DMG file here and let me minimize the browser and you will see this kind of window here in order to install Java jdk using this window you just need to click on this PKG file so I'm going to click on this PKG file which is going to start the installation process let me minimize this window also so this is the installer window we are going to just click on continue on the first window here and then it says this will take around 336 megabyte of space on your computer Compu I'm okay with it so I'm going to click on install here and then I need to give my macbook's password so I'm going to provide the password here and then click on install software which is going to start the installation of Java jdk on my Mac operating system and in few seconds this window will appear which says install succeed so now I can close this window so basic installation of java has been done when I press on close it says do you want to move jdk installer to bin yes because the Java installation is finished we can move this uh DMG file to the bin so I'm going to just click on that and that file will be moved to the bin now Java jdk is installed on my Mac operating system now the next step in this process is to set the Java home so for that what we we need to do we need to first of all find out where Java is installed on our Mac operating system so for that we are going to open the terminal so just click on this Spotlight icon and then search for terminal and then open the terminal from here so generally once you install Java jdk its location is for/ USR SL libexec slash Java home so Java uncore home and then you need to give hyphen and then capital V and it's going to give you the version of java which you have installed so this is the version which we have installed which is Java 20 1.0.1 once we know the version of uh Java so now in The Next Step what we need to do is we need to set or export the path of java home in our bash RC file or zshrc file now if you are using the newer version of Mac operating system most probably by default your Mac terminal is using zsh so we are going to set the Java home in the zshrc file now this zshrc file is located in your home folder so when you do p D and when you open the terminal for the first time this is the home folder of your Mac operating system or for your particular user right and this zshrc is located in this directory so how to uh know that you can do LS space hyphen Al and then press enter and you will be able to see this kind of file which says Dot zshrc now if this file is not present you don't need to worry about it we will create a new. zshrc file so if this file is present we will add our location to it if it's not present we will first create this file and then we are going to add our export now you can use any Editor to uh edit or create this file if this zshrc file is not there you can uh use this touch command and then write do zshrc and then press enter and it's going to create your do zshrc file in my case it's already present so I'm not going to give this command the next command is using a text editor you need to open this file you can use Nano to open the dot zsh file or if you are the fan of text editor then you can use open also so just write open and then write do zshrc which is the name of this file and then press enter which is going to open this zsh file using the text editor let me make this uh text a little bit bigger so you can see here so I already have one export here in your case if you have created this file for the first time you will not see any export here it will be blank what you need to do here is you need to copy and paste these two lines here I'm going to paste these two lines in the description of this video also so you can directly copy them and paste it into your terminal so the first command is export Java unor home is equal to dollar and then this is the path which we have uh seen in the terminal so we have used this path right user SL lib exact SL Java home space hyphen version and we got this version in my case right 21.0 point1 so here we have given the same path hyphen version and instead of this version you need to give the version which you see after giving this command so in my case the version is 2.0.1 so I'm going to replace this version with 21.0 point1 so let me just write 21. 0.1 here and then in the next line you need to uh give this command which is export space path is equal to Dollar Java home/ bin colon dollar path right so these two lines you need to copy and paste and don't forget to change the version with the version which you have once you are done you can save this file so I'm going to just uh click on the file option and then click on Save which is going to save this shrc file and then I'm going to close this once this is closed you can verify that your changes are saved by just giving the same command once again is openspace do zshrc and I can see that my changes are already there so I know that my changes are saved right once your changes are saved the next command you need to write here is this one so let me clear the terminal because uh it's full so after uh saving your export you just need to give this command which is source and then give the name of your file which is do zshrc and then press enter if you don't give this command then do zshrc will not load in the current terminal so if you don't give this command just close your terminal and then reopen the terminal once again okay so you can also do this so I'm going to just close this terminal and then quit from this terminal and then once again open the terminal and once the terminal is open I can check the Java home is set or Not by giving Echo command so I'm going to just give echo dollar Java uncore home and then press enter and it's going to give you the location of java home in my case it's uh Library SL Java SL Java virtual machine SL jdk 21. jdk contents for slome okay so if you have followed all the step which I have shown you you will see this kind of output now once uh Java home is set and Java is installed we can also check the version of java so you can give this command which is Java space hyphen version and then press enter and it's going to give you the version of java which is 2.0.1 in my case so Java is now successfully installed on my Mac operating system so now let's try to create a Java file where we will uh write a very simple hello world program and then we are going to compile it and then we are going to try to run that Java program so I'm going to clear the terminal and now you need to navigate to the folder where you want to uh create your Java project so right now I'm in my home directory you can uh just do LS here and here I have a few folders right so let's say I want to create a new Java project in the documents folder so I'm going to go or CD into my documents folder and then here let me create a folder called let's say I'm going to just create a folder using mkd command and then uh I will just name my uh folder as projects here and then press enter which is going to create this my project directory in the documents folder I can do LS once again and then you can see this my project directory is created so I'm going to go inside this directory CD and then the name of the directory and here I'm going to create a new Java file so in order to create a new Java file you can can uh use Touch command so just write touch and then the name of your Java file for example I'm going to create a file with the name hello and then the extension for this will be Java okay so just write touch space hello. Java which is going to create this hello. Java file in your my project directory so when I do LS you can see hello. Java file is created I can also go to my finder and then go to uh my uh documents folder where I have created this my projects folder where I can see that this hello. Java file is there so let me uh do this side by side so you will be able to see the output also in this Finder right so we have created this hello. Java file now uh you can open this hello. Java file by just right click clicking on it and then you can use open with and then use text edit and it's going to open this hello. Java file so once this hello. Java file is uh created I'm going to uh paste this very simple Java program here you can find this program anywhere on Internet it's just printing hello world using Java right so just write public space class space hello and and then in this class you need to create a main method with public stated void Main and then uh you need to uh write system. out. print line and in the parenthesis and between the codes just write hello world as I said you will find this program anywhere on internet so you don't need to worry about it just copy and paste this kind of hello world program in your Java file and then I'm going to save this file to save this file to save this file you just need to click on file and then click on uh save or just press command s to save the file once you have saved your program in order to compile your Java file you need to run this command which is Java C it's not a Java command it's a Java C command if you want to compile a Java file so just write Java C and then the name of your Java file in my case it's hello. Java right this is the name of the file hello. Java I'm going to press enter which is going to compile this hello. Java program and it's going to create this file which is hello. class this is the output of your compilation of your Java file once you see hello. class file created now it's time to run your program to run the program write Java and then the name of the file you need don't need to give the extension do class here you can just write hello here without class and then press enter and it's going to print hello world which is the output of my compilation of my Java program so this is how uh you can run your Java programs using the Java command and you can compile your Java programs using the Java C file so this is how you can download and install Java jdk set Java home and compile your Java programs on your Mac operating system I hope you've enjoyed this video and I will see you in the next video
Info
Channel: ProgrammingKnowledge
Views: 92,701
Rating: undefined out of 5
Keywords: Java (Programming Language), Installation (Award-Winning Work), Java Development Kit (Software), Maker, How-to (Website Category), Java (Software), Tutorial, Desktop, Mac, Apple Mac, OS X, Mac OS X, JAVA_HOME, JDK, install Java, install Java JDK, macOS, JDK on macOS, How to install Java with Mac?, How do I enable Java on my Mac?, How to download Java for Mac 2023?, How do I install Java on Safari Mac?, java download, download java mac, install java mac m1, install java mac terminal
Id: PQk9O03cukQ
Channel Id: undefined
Length: 16min 48sec (1008 seconds)
Published: Mon Jan 01 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.