Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
How to Install Java on Windows, Linux and macOS?
Next article icon

How to Install Java on Windows, Linux and macOS?

Last Updated : 07 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Java is a versatile programming language widely used for building applications. To start coding in Java, you first need to install the Java Development Kit (JDK) on your system. This article provides detailed steps for installing Java on Windows 7, 8, 10, 11, Linux Ubuntu, and macOS.

Download and Install Java - Windows Operating System

Here, we will discuss how to download and install Java on a Windows 64-bit Machine and set up the environment to run the first Java program on the command prompt. The process is the same for all Windows i.e. 7, 8, 10, and 11.

Step 1: Visit the official Oracle website https://www.oracle.com/in/java/. Click on the "Download Java" icon as shown in the below image.

Install-Download-Java-1


Step 2: Now you can see the latest version is JDK 23 and there are options for Linux, macOS, and Windows. Click on the Windows option and then click the x64 Installer option to download the .exe file for 64-bit Windows OS.

Install-Download-Java-2

You can simply use this link to download Java for Windows 64 Bit. After successfully downloading JDK 23, now we need to install the Java on our Windows System.

Step 3: Go to Downloads and double-click on that downloaded jdk-23_windows-x64_bin.exe file. So now Java Installation Wizard get open and then click Next button.

Install-Download-Java-3


Again click on the Next button to install JDK.

Install-Download-Java-4


The installation will begin as shown below:

Install-Download-Java-5


The Java installation is successfully completed as shown below. Now click on "close" to finish.

Install-Download-Java-6


Step 4: Now we will set the environment variables for Windows OS. Open the C drive, go to Program Files > Java > jdk-23 (or your installed version) > bin folder. Now, copy the path and we will use this path when configuring the environment variables.

Set-Environment-Variables-Windows-1


Search for environment variable on your system, then click on the Environment Variables button.

Set-Environment-Variables-Windows-2


In the system variable section, select the path variable and then click the option Edit.

Set-Environment-Variables---Windows-3


Paste the path that copied earlier, and click OK to save the changes.

Set-Environment-Variables-Windows-4


Step 5: Verify the Installation. Open command prompt and type the below command to verify the Java version that is installed in the system.

java --version

Verify-Installation---Windows


Now let us run our first Java program, to do this, follow the below steps:

Step 1: Open any Drive, and in the drive, create a text file and then change the file name with .java extension as shown below:

file.java

Step 2: Now, write a simple Java code in notepad.

  • Right-click on the file.java and then select open with > Notepad.
  • Inside the file, write the Java code.
Run-Java-Code-1


Important Point: In Java, the class name should be equivalent to the file name. In this case, the file name is file.java, so the class name inside the file should be file.

Step 3: Now, go to the directory where your Java file is saved.

Open command prompt and navigate to the D drive, where the file.java is located. To do this, type "dir" as shown below:

Run-Java-Code-2


Step 4: The dir command display all the contents of the directory.

Run-Java-Code-3


Step 5: Compile the Java program. The javac command is used to compile the Java program.

Syntax:

javac filename.java

To run the program use the below command:

java filename

Here, in this case the filename is file.

Run-Java-Code-4


We have successfully run our first Java program on Windows OS.

Download and Install Java - Linux

Step 1: Visit the official oracle website https://www.oracle.com/in/java/.

  • You will need to accept the terms of Oracle’s license agreement before downloading.
  • On the download page, accept the Oracle Binary Code License Agreement for Java SE.
  • Select the Linux version.
  • If you are using a standard 64-bit system, select the file for x64 architecture. If you are using an ARM-based system, select the file for arm64.
  • Download the .tar.gz file for Linux.

This is the format used for installing Java on most Linux systems.

Step 2: Now, open the terminal on your Linux system and navigate to the folder where you downloaded the file.

cd ~/Downloads

Use the below command to extract the contents of the .tar.gz file.

tar -xvzf jdk-23_linux-x64_bin.tar.gz

Move the extracted folder to the /opt directory:

sudo mv jdk-23 /opt/

Step 3: After Installation, you need to set up the environment variable for Linux.

Open the terminal and type the below command to open the shell configuration file.

nano ~/.bashrc

Add the following lines at the end of the file.

export JAVA_HOME=/opt/jdk-23

export PATH=$JAVA_HOME/bin:$PATH

Apply the changes by running the below command:

source ~/.bashrc

Step 4: Now, verify the installation on Linux by running the below command:

java --version

The installed Java version on Linux will be displayed.

Download and Install Java - macOS

Step 1: Visit the official oracle website https://www.oracle.com/in/java/. Select the macOS version and download the .dmg file.

Step 2: Now open the .dmg file and double-click the installer package (.pkg) to begin the installation process. Then follow the instructions to complete the installation.

Step 3: Setting the environment variable on macOS is optional, but it is recommended, if you want to use Java for development purposes (e.g., running Java-based applications, using tools like Maven or Gradle).

To set the environment variable foe macOS, open the Terminal and edit the shell configuration file (e.g., .zshrc):

nano ~/.zshrc

Add the following lines at the end of the file to set the Java_Home.

export JAVA_HOME=$(/usr/libexec/java_home)

export PATH=$JAVA_HOME/bin:$PATH

Save and close. To apply the changes, run the following command:

source ~/.zshrc

After these steps, Java should be installed and ready to use on your macOS system.

Step 4: Now open the terminal and run the below command to verify the Java version on macOS:

java --version

You will see an output showing the latest Java version that you have installed on your macOS system.


Next Article
How to Install Java on Windows, Linux and macOS?

R

Rajnis09
Improve
Article Tags :
  • Java
  • How To
  • Installation Guide
  • java-basics
  • how-to-install
Practice Tags :
  • Java

Similar Reads

    How to Install Apache Maven on Windows, macOS, and Linux?
    Apache Maven is a comprehensive build automation tool widely used for managing and building Java projects. It simplifies the process of managing project dependencies and building projects through a standardized approach. This article provides step-by-step instructions to install Apache Maven on Wind
    4 min read
    How to Set Java Path in Windows and Linux?
    PATH is an environment variable that is used by Operating System to locate the exe files (.exe) or java binaries ( java or javac command). The path once it is set, cannot be overridden. The PATH variable prevents us from having to write out the entire path to a program on the Command Line Interface
    4 min read
    How to Install Java on macOS?
    The Java Development Kit (JDK) is an essential tool for developers working with Java. It provides the necessary tools and libraries to build, compile, and run Java applications, making it a cornerstone for efficient and effective Java development. Without the JDK, writing and testing Java programs w
    7 min read
    How to Install NetBeans Java IDE on Windows?
    NetBeans IDE is a Free open-Source, Cross-plate form Integrated Development Environment (IDE) with built-in support for the JAVA Programming Language. It can run any machine which consists of the Java Virtual Machine (JVM). It consists of many features for application development as follows: Drag
    2 min read
    How to Install Java Applet Viewer on Linux?
    Applet viewer is a command-line program to run a java applet. It helps you to test an applet before you run it in the browser. The applet's code gets transferred to the system & then the Java Virtual Machine (JVM) of the browser & executes that code. In this article, we will look into the pr
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences