Sub topic 4
Download and Install the JDK
The Java Development Kit (JDK) contains the tools you need to create and run Java programs. In this chapter, you will download and install it on your computer.
The examples use JDK 21. It is a long-term support (LTS) version, which means it receives updates for an extended period. If a course or project asks for a different JDK version, use that version instead.
You should already know your operating system and computer architecture. The operating system is the software that manages your computer, such as Windows, macOS, or Linux. Architecture is the type of processor your computer uses, such as x64 or ARM64.
Download or install the right package
A package is a set of files prepared for installation. For Windows and macOS, this chapter uses Eclipse Temurin, a JDK provided by the Adoptium project. For Ubuntu Linux, it uses Ubuntu’s own software packages.
Downloading a file does not always install it. On Windows and macOS, you must open the downloaded installer and follow its steps. On Linux, you can use a package manager, a tool that downloads and installs software for you.
Windows
- Open a web browser and go to [adoptium.net/temurin/releases](https://adoptium.net/temurin/releases/).
- Select JDK 21, Windows, and your architecture.
- Choose a JDK download, not a JRE download. A Java Runtime Environment (JRE) runs Java programs but does not include all the tools needed to create them.
- Download the
.msiinstaller. If one is not offered for your selection, check your operating system and architecture selections. - Open the downloaded file. It is usually in your Downloads folder.
- Follow the installer’s steps. The default choices are suitable for this tutorial.
- If Windows asks for permission to make changes, approve it only if you started the installer you downloaded from Adoptium. Finish the installation.
Some computers require an administrator account to install software. An administrator account has permission to make system-wide changes. If this is a work or school computer and you cannot approve the installation, ask its support team for help.
macOS
- Open a web browser and go to [adoptium.net/temurin/releases](https://adoptium.net/temurin/releases/).
- Select JDK 21, macOS, and your architecture. Apple silicon uses ARM64, which the site may call
aarch64. Intel Macs use x64. - Choose a JDK download, not a JRE download.
- Download the
.pkginstaller. - Open the downloaded file from your Downloads folder.
- Follow the installer’s steps. The default choices are suitable for this tutorial.
- If macOS asks for an administrator name and password, enter them. Finish the installation.
If macOS warns that it cannot confirm the installer is safe, do not bypass the warning. Check that you downloaded the file from Adoptium. If you still have concerns, ask for help before opening it.
Ubuntu Linux
For Ubuntu 24.04, open a terminal and run:
sudo apt update
sudo apt install openjdk-21-jdkA terminal is a window where you type commands. The apt package manager gets software from Ubuntu’s configured software sources. The first command updates its list of available packages; the second installs JDK 21.
The word sudo requests administrator permission. You may be asked for your account password. As you type it, the terminal will not show the characters. Press Enter when you have finished. If asked to confirm the installation, follow the prompt.
Other Linux systems
Package names and commands differ across Linux systems. Check your system’s documentation for how to install JDK 21 through its package manager.
You can also use the Temurin archive from [adoptium.net/temurin/releases](https://adoptium.net/temurin/releases/). An archive is a file that holds other files. Select JDK 21, Linux, your architecture, and a JDK .tar.gz download. Use your file manager to extract it, then move the extracted JDK folder to a lasting location in your home folder, such as a folder named jdks.
Remember where you put that folder. Extracting an archive does not necessarily make its commands available in the terminal; the next chapter covers that step.
If installation does not finish
- If the installer says it is not compatible with your computer, check the operating system and architecture you selected, then download the matching package.
- If you cannot get administrator permission, ask the person or team that manages the computer.
- If a download or installation fails because of a network problem, check your connection and try again.
- If you chose a different JDK version for a course or project, check that the package matches the version you need.
After installation, you will make sure the JDK commands are available in your terminal. Installing the files and making commands available are separate steps.
Exercise
You are using an Intel Mac and need JDK 21. What should you select on the Temurin download page?
Show answer
Select JDK 21, macOS, x64, and a JDK download. Download the .pkg installer and follow its steps.