Sub topic 4
Download and Install the JDK
The Java Development Kit, or JDK, is the set of tools used to make and run Java programs. In this chapter, you will download a JDK and put it on your computer.
You should already have chosen a JDK version for your operating system and computer type. Keep those choices nearby. You will need them on the download page.
The examples use Eclipse Temurin, a JDK from the Adoptium project. If you chose a different JDK, use its provider’s official instructions. The screens and file names may differ.
Before You Download
An installer is a file that guides you through putting software on your computer. On Linux, this chapter uses an archive, a file that holds a collection of other files.
Use the section for your operating system:
| Operating system | File to download | How you will install it |
|---|---|---|
| Windows | A JDK installer ending in `.msi` | Open the installer and follow its steps. |
| macOS | A JDK installer ending in `.pkg` | Open the installer and follow its steps. |
| Linux | A JDK archive ending in `.tar.gz` | Extract its files into a folder. |
Before you begin, make sure you have an internet connection and some free disk space. Allow at least 1 GB of free space for the download and installation.
Windows and macOS may ask for an administrator password. This is the password for a computer account allowed to make changes for all users. On a school or work computer, you may need to ask the person who manages it for help.
Download Eclipse Temurin
Open the official Temurin releases page:
https://adoptium.net/temurin/releases/
The page may change over time, but look for choices for the JDK version, operating system, and computer type you selected earlier.
- Select your chosen JDK version. For example, select version 21 if that is the version you chose.
- Select your operating system and computer type.
- Select JDK, not JRE. A JRE is a smaller set of tools for running Java programs; it does not include everything needed to create them.
- Choose the file type for your operating system from the table above.
- Download the file and wait for the download to finish.
The file name will contain details such as the version and computer type. It may be long. The exact name will depend on the release you download.
Keep the downloaded file until the installation is complete. You can delete it afterward if you want to save space.
Install on Windows
Follow these steps if you downloaded the Windows .msi installer. Otherwise, skip to your operating system’s section.
- Open File Explorer and find your downloaded
.msifile. It is usually in the Downloads folder. - Double-click the file to start the installer.
- If Windows asks whether you want to allow the installer to make changes, check that it is the Temurin installer you downloaded. Continue only if you trust it.
- Read the opening screen, then continue through the license and setup screens.
- If the installer shows an installation folder, note its location. The default location is fine for most learners.
- If the installer offers a choice to add Java to
PATH, you may enable it.PATHis a list of folders that the computer searches for commands. You may also see an option to setJAVA_HOME, a setting that can point other tools to the JDK. The next chapter covers making Java commands available. - Start the installation. If Windows asks for an administrator password, enter it or ask your computer’s administrator for help.
- Wait for the installer to finish, then close it.
The screens and options may look a little different from these steps. If you do not see a PATH or JAVA_HOME option, you can continue. You will handle command settings in the next chapter.
Find the installation folder
The installer may show the folder where it will place the JDK. Write that location down before continuing.
If you did not note it, open File Explorer and look in the following folder, which is a common location for Temurin installations:
C:\Program Files\Eclipse AdoptiumInside it, look for a folder whose name includes the JDK version you installed. The exact folder name can vary. Record the full folder location; it may be useful in the next chapter.
If the folder is not there, you may have chosen a different location during installation. Check that the installer finished without reporting an error.
Install on macOS
Follow these steps if you downloaded the macOS .pkg installer.
- Open Finder and go to your Downloads folder.
- Double-click the downloaded
.pkgfile. - Follow the installer’s screens. Read the license and continue if you agree to it.
- Use the standard installation location unless you have a reason to change it.
- When asked, enter the password you use to allow changes on your Mac. Depending on your Mac’s settings, you may be able to approve the installation another way.
- Wait for the installer to report that it has finished, then close it.
If macOS says it cannot confirm that the installer is safe, do not turn off your Mac’s security settings to proceed. Check that you downloaded the file from the official site. If you are still unsure, ask your computer’s administrator for help.
Find the installation folder
Temurin normally installs JDKs under this folder on macOS:
/Library/Java/JavaVirtualMachinesIn Finder, choose Go, then Go to Folder, and enter that location. Look for a folder whose name contains temurin and your JDK version.
Inside that folder, the JDK’s home folder is normally Contents/Home. For example, if the Temurin folder is named temurin-21.jdk, its home folder is:
/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/HomeYour folder name may be different. Record the path you find, including Contents/Home. You may need it in the next chapter.
Install on Linux
On Linux, you will extract the Temurin archive into a folder in your home directory. Extracting means taking the files out of an archive. Your home directory is your personal folder on the computer.
This method puts the JDK in your own files. It does not need an administrator password. It also does not automatically make the Java commands available in every terminal; that is covered in the next chapter.
Prepare the archive
- Find the Temurin
.tar.gzJDK archive you downloaded. It is usually in your Downloads folder. - Rename the downloaded file to
temurin-jdk.tar.gz. Keep the full.tar.gzending. - Make sure the renamed file is directly inside your Downloads folder, not inside another folder.
The commands below expect that exact name and location. If your system uses a different name for its Downloads folder, adjust the path to match.
Extract the JDK
Open a terminal and run these commands:
mkdir -p "$HOME/jdks"
tar -xzf "$HOME/Downloads/temurin-jdk.tar.gz" -C "$HOME/jdks"
ls "$HOME/jdks"Here is what the commands do:
mkdir -pcreates a folder if it does not already exist.$HOMEstands for the path to your home directory.tar -xzfextracts the.tar.gzarchive.-Ctellstarwhich folder should receive the extracted files.lslists the items in that folder.
The list should include a new JDK folder. Its name usually starts with jdk and includes the version. The exact name depends on the release you downloaded. If the jdks folder already contained other JDKs, be careful to identify the new one.
Record the full path to that folder. For example, if your home folder is /home/sam and the extracted folder is named jdk-21.0.7+6, the path is:
/home/sam/jdks/jdk-21.0.7+6Your path will probably have a different user name, version, or both.
If the terminal says it cannot find the archive, check its name and location. If it says tar is not available, follow your Linux system’s documentation for installing that tool, or ask your computer’s administrator for help.
Know What You Installed
The JDK is now stored in a folder on your computer. That folder contains the Java tools you will use later, including the compiler and the runtime. The compiler changes Java source files into a form Java can run. The runtime runs that compiled program.
Installing files and making commands available are separate steps. Even if installation finished, a terminal may not yet know where to find the JDK. You will set that up next, then check the installed tools in a later chapter.
It is also possible to have more than one JDK on a computer. Installing a new one does not necessarily remove an older one. Keep the version and installation path you recorded so you can identify the JDK you just installed.
Before Moving On
You are ready for the next chapter when you have:
- Downloaded the JDK file for your chosen system.
- Finished the installer on Windows or macOS, or extracted the archive on Linux.
- Recorded the JDK version and its installation folder.
- Kept any administrator or installation error to discuss with your computer’s administrator if the process did not finish.
You do not need to write or run a Java program yet.
Exercise
You downloaded a Temurin file labeled JRE instead of JDK. Should you install it for this tutorial?
Show answer
No. Download the JDK instead. The JDK includes the tools needed to create Java programs.
Exercise
Your JDK installer finished, but you have not checked whether terminal commands can find Java. What should you do next?
Show answer
Keep the JDK installation path and move on to making the Java commands available. You will check the tools afterward.