How To Install Java On Mac | Install Java Jdk On Macos

  • 18-Apr-2022

Hey, guys in this video I'm going to show you how you can download and install Java on your Mac operating system. So let's get started and let's see how we can install Java on our Mac operating system. So to start with, we are going to verify if any other version of Java is installed on your Mac operating system or not so to do that just click on this search icon and then search for terminal. And once this terminal ICANN is visible just click on the terminal icon, which is going to open the terminal.

On your Mac operating system here to verify. If Java is installed, you need to just write Java - version command and then + Enter. And then you will see this kind of output, which says, no, Java, Runtime present, requesting install.

And you will see this kind of pop-up also if Java is installed, you will see the version of Java, which is installed on your Mac operating system. So what we are going to do is we are going to click on this button, which says more info. And this is going to open the official. Oracle website and here you will be able to find directly the version of Java, which is the latest version, which is Java SE 14 at the time of making this video. If you want to search for this location manually, then you can search for Oracle Java JDK on your favorite browser. And the first language will appear here will be this website link. So I'm going to just click on this link, which will redirect me to the same page, which I have seen here.

Ok. So here, what you need to do is you need to click on JDK. Download and as I said at the time of making this video, the latest version is Java SE 14.

So we are going to install the version 14 on our Mac operating system. Now here when we will scroll down, you will be able to see the packages for different operating system. So we want to install it on our Mac operating system. So we are going to choose the macOS installer. So just click on the link, which is in front of the Mac installer, which we'll be the file with the dot DMG extension. So I'm going to be just.

Click on this link, and then just check this checkbox and then click on the download button. So this is going to start the download of this JDK file on your Mac operating system. And then just decide a file and then click on OK, which is going to start the download. So this is around 176 megabyte files. So it will take some time to download. So once this DMG file is downloaded you just need to click on this DMG file, which is going to open this kind of installation, wizard, let me just minimize the browser. And the terminal also.

So once this window opens, you will be able to see this JDK, 14 point. 0 point 1 dot, pkg file. So 14 point 0 point 1 is the version we are going to install right.

So just double-click on this JDK package file, which is going to start this installation wizard. So here just click on continue here and then click on the installation button. And then you just need to give your Mac operating systems' password. So just provide the power us word of your Mac operating system, click, install software. Which is going to start the installation of Java on your Mac operating system.

And in few seconds, you will see this message. It says, install succeeded, which means the Java JDK is successfully installed on your Mac operating system. So just close this file.

And then you can just click on move to tress, which is going to move this file to trash, because we already have installed Java on our Mac operating system. Now once Java is installed on your Mac operating system. You can also set the Java home.

Environment variable on your Mac operating system. So what I'm going to do is I'm going to just quit this terminal, and I'm going to open the terminal once again. So just search for the terminal once again, and I'm going to open the terminal once again.

And now I have all the commands, which I have listed here. So to know, the location of your Java home, you just need to give this command I'm going to provide all these commands in the description of this video also. So this command is going to give you. The Java home path, so I'm going to just give this command and then press ENTER. And you can see we are going to set this Java home path into our environment, variable as Java home. So once we know the Java home path, we can give this next command.

So we just need to open this dot, Bash underscore profile file with any editor of your choice. So you can give this command open till they power. Slash dot, bash underscore profile, or any editor of your choice. You can list out this bash profile in your home. Directory also so just open your terminal and just give LS - all command, and you will be able to see this, bash profile file here also, ok. So what I'm going to do is I'm going to just clear this terminal, and then I'm going to open this file using my editor, which is Visual Studio Code, so I'm going to just write code.

And then the path of this bash underscore profile, you can as I said, use open also to open this file or whim to open this file or NATO to open this file. So the editor choice is yours. So.

I'm going to open it with the code editor, which is Visual Studio Code in my case. And here at the very bottom, I'm going to export this path. So to export this path, you just need to just write export Java home in capital, all in capital right? So just at the end just right export.

Java home is equal to and the path, which you have found using this command, which is this part, so I'm going to just copy this path up to home from, but the terminal and then paste it after equals to sign. Okay. So once you are.

Done, you can just save this file, so I'm going to be just save this file, and then I'm going to move to the next command, which is source till the /throe file is going to refresh your bash profile in the terminal. So you, if next time, when you give this Java home command, it's going to give you the value of that till they forward, slash dot, bash underscore profile and then press enter. And now you can echo the value of your Java home variable. So just write echo and then dollar Java, underscore home. All. In capital press, ENTER, and it's going to give you the value of Java home. Also, you can give the Java version command, so I'm going to clear the terminal.

And this time I'm going to give the Java - version command and then press, ENTER, and it's going to give me the version of Java, which is installed on my Mac operating system. So as you can see, we have installed Java, 14 point, 0.1, so it's going to give us this version. You can also give Java C - version command. So Java C is used to compile or build your. Java programs and it's going to give you this kind of version.

So this also is fourteen point. Zero point. One now let's do something interesting let's, create a file Java file.

And we are going to compile this file using Java C and run our program using Java command. So what I'm going to do is I'm going to CD to my desk top folder. So to create a Java file, you just need to navigate to the location where you want to create this file I want to create this file into my desktop folder. So I'm going to be just. Go to my desktop folder, right now, I don't have any file in my desktop folder. So I'm going to create it using touch command, and then I'm going to write the name of my file, which is hello world file. And then you need to give the extension Java to it.

Okay. So touch HelloWorld dot, Java. And once you do that, you can see when you do LS. This file name is there, which means this file is created.

Now you can open this file using any editor of your choice. You can use Eclipse IDE or NetBeans or IntelliJ IDEA.Also, for compiling your Java code, I'm going to use code editor, which is Visual Studio Code editor for compiling and editing this file. So just write code and HelloWorld dot, Java file name, and it's going to open your hello world.java file into an editor.

It can be any editor as I said. Now, here I'm going to just give a simple. Hello world code. This code, you can find easily on internet anywhere, so I'm going to not go into the details of this program. We are just interested in compiling and running this. Program so this is just printing HelloWorld on the terminal when it's compiled once you have this code, just save this code and then go to the terminal once again and to compile your code, you just need to give Java C and the name of your file, which is HelloWorld dot Java in our case and must you do that you can see that this file is created in your folder.

Ok? So if you see this file that means your compilation has both worked successfully. So we just need to run it using the Java command. So once. You see this file, you can give Java and the name of your executable file, which is hello world. In our case, you don't need to give this dot class extension after your hello world program.

You just need to give this name, which you see here before dot class, ok, so Java and then HelloWorld. And when you press Enter, you will see. Hello world is printed.

That means our java and Java c commands are working. So as I said, java, c is for compiling your program and java command is for running your java program. This is how you can download and install java on your Mac operating system.

I hope you've enjoyed this video, and I will see you in the next video.

Leave a Reply

Your email address will not be published. Required fields are marked *