What the Java Development Kit is and why you might need it
The Java Development Kit (JDK) is a set of tools that lets you write, test, and run programs written in the Java programming language. If you are setting up a wired network, managing network services, or working with software that requires Java to run, you will need the JDK installed on your computer. The JDK includes a compiler (which turns your code into something the computer can run), a runtime environment, and other utilities.
You do not need the JDK just to use Java programs — many applications run fine with only the Java Runtime Environment (JRE). But if you are writing code, testing applications, or administering systems that depend on Java, the JDK is what you install.
Key Takeaways
- read the JDK from Oracle's official website (oracle.com/java) or use OpenJDK, a free alternative maintained by the open-source community.
- Choose the version that matches your operating system: Windows, macOS, or Linux, and whether your computer runs 64-bit or 32-bit architecture.
- Run the installer and follow the on-screen prompts, then verify the installation by opening a terminal or command prompt and typing java -version.
- Set the JAVA_HOME environment variable so your system knows where the JDK is located — this step is required for many development tools to work correctly.
Choosing between Oracle JDK and OpenJDK
Oracle JDK is the official version maintained by Oracle Corporation. It is free to read and use for development, but Oracle's licensing terms restrict commercial use in some cases. If you are building software to sell or deploy in a business, read Oracle's current license agreement before committing to it.
OpenJDK is a free, open-source version of Java maintained by the community and supported by companies like Red Hat and Amazon. It is functionally equivalent to Oracle JDK for most purposes and has no licensing restrictions. If you are unsure which to choose, OpenJDK is the safer option — it works the same way and costs nothing either way.
Downloading the right version for your computer
Visit oracle.com/java/technologies/downloads if you want Oracle JDK, or openjdk.java.net if you prefer OpenJDK. Both sites ask you to choose your operating system and architecture. Most modern computers run 64-bit, but if your computer is older, you may have 32-bit. You can check this on Windows by opening Settings, going to System, and looking at "System type." On macOS, click the Apple menu, select About This Mac, and look at "Processor." On Linux, open a terminal and type uname -m.
read the installer file — it will be named something like jdk-21.0.1_windows-x64_bin.exe on Windows, jdk-21.0.1_macos-x64_bin.dmg on macOS, or a .tar.gz file on Linux. Save it somewhere you can find it, like your Downloads folder.
Installing on Windows
Double-click the .exe file you downloaded. A window will appear asking where you want to install the JDK. The default location is usually C:\Program Files\Java\jdk-21.0.1 (the version number may differ). Click Next and follow the prompts until the installation finishes. Windows will add the JDK to your system automatically.
To verify the installation worked, open Command Prompt (search for "cmd" in the Start menu), type java -version, and press Enter. You should see output showing the Java version number. If you see "java is not recognized," the installation did not complete or the JDK is not in your system path — try restarting your computer and trying again.
Installing on macOS
Double-click the .dmg file. A window will open showing the JDK installer. Double-click the installer icon inside and follow the prompts. macOS will install the JDK in /Library/Java/JavaVirtualMachines/ automatically. The process takes a few minutes.
Open Terminal (search for "Terminal" in Spotlight or find it in Applications > Utilities), type java -version, and press Enter. You should see the version information. If the command is not found, restart your computer and try again. macOS sometimes needs a restart to update the system path.
Installing on Linux
The process varies slightly by Linux distribution. On Ubuntu or Debian-based systems, you can install OpenJDK directly from the package manager by opening a terminal and typing sudo apt update followed by sudo apt install openjdk-21-jdk (replace 21 with whatever version is available). This is faster and simpler than downloading manually.
If you downloaded a .tar.gz file instead, extract it to a location like /opt/java by typing tar -xzf jdk-21.0.1_linux-x64_bin.tar.gz -C /opt/java. Then you will need to set the JAVA_HOME environment variable (see the next section). Verify the installation by typing java -version in the terminal.
Setting the JAVA_HOME environment variable
Many development tools and applications look for a variable called JAVA_HOME to find where the JDK is installed. On Windows, right-click This PC or My Computer, select Properties, click Advanced System Settings, then Environment Variables. Click New under System Variables, type JAVA_HOME as the variable name, and paste the path to your JDK installation (for example, C:\Program Files\Java\jdk-21.0.1) as the value. Click OK and restart your computer.
On macOS, open Terminal and type nano ~/.zshrc (or ~/.bash_profile if you use an older version). Add the line export JAVA_HOME=$(/usr/libexec/java_home), press Ctrl+O to save, then Ctrl+X to exit. Close and reopen Terminal. On Linux, open a terminal and type nano ~/.bashrc, add the line export JAVA_HOME=/opt/java/jdk-21.0.1 (adjust the path to match where you installed it), save, and close. Type source ~/.bashrc to explore the change when ready.
Verifying everything is working
Open a terminal or command prompt and type java -version. You should see output like "java version 21.0.1" or similar. Then type javac -version to verify the compiler is installed — you should see "javac 21.0.1" or similar. If both commands work, the JDK is installed and ready to use.
If you get "command not found" or "is not recognized," the JDK is installed but not in your system path. Restart your computer — most systems need a restart after installation to update the path. If restarting does not work, double-check that you downloaded the correct version for your operating system and architecture, and that the installation completed without errors.
Frequently Asked Questions
Do I need to install both JDK and JRE?
No. The JDK includes the JRE, so installing the JDK gives you both. You only need the JRE alone if you want to run Java programs but will never write or compile code.
What is the difference between JDK versions like 17, 21, and 23?
Java releases a new version every six months. Versions 17 and 21 are "long-term support" (LTS) versions that receive updates for many years. Other versions get updates for only six months. For most purposes, use the latest LTS version — currently version 21 — unless a specific process requires a different version.
Can I have multiple JDK versions installed at the same time?
Yes. Install them in different folders and set JAVA_HOME to whichever one you want to use by default. You can also switch between versions by changing the JAVA_HOME variable or by typing the full path to a specific version's java command.
What if the installer says I do not have permission to install?
On Windows, right-click the installer and select "Run as administrator." On macOS or Linux, you may need to use sudo when running installation commands. If you are on a work or school computer, contact your IT department — they may have restrictions on what software you can install.
Is it safe to delete the installer file after installation?
Yes. Once the JDK is installed, you do not need the installer file anymore. You can delete it to free up disk space.