TP1.1 — Installation of Java JDK 17
Objectives
This practical work will allow you to:
- Install the JDK 17 (Java Development Kit) on your operating system
- Configure environment variables (
JAVA_HOME,PATH) - Verify the installation with the commands
java,javac, andwhich java - Understand the difference between JDK, JRE, and the different distributions
Estimated duration: 20-30 minutes
Why Java 17?
| Reason | Detail |
|---|---|
| LTS (Long Term Support) | Long-term support by Oracle and the community (until 2029+) |
| Spring Boot 3.x | Minimum version required by Spring Boot 3 |
| Modern features | Records, sealed classes, pattern matching, text blocks |
| Stability | Proven production version since 2021 |
- Eclipse Temurin (Adoptium) — Recommended, free, open source
- Oracle JDK — Free for development, commercial license in production
- Amazon Corretto — Free, maintained by Amazon
- Azul Zulu — Free, certified
We recommend Eclipse Temurin for this course.
Installation on Windows
🪟 Click here for Windows installation (graphical method)
Step 1: Download the JDK 17
- Go to https://adoptium.net/
- Select:
- Operating System: Windows
- Architecture: x64
- Package Type: JDK
- Version: 17 (LTS)
- Click on "Latest LTS Release" to download the
.msifile
Step 2: Install the JDK
- Double-click the downloaded
.msifile - Follow the installation wizard
- IMPORTANT: During installation, check these options:
- ✅ Add to PATH
- ✅ Set JAVA_HOME variable
- ✅ Associate .jar files
┌──────────────────────────────────────┐
│ Eclipse Temurin JDK 17 Setup │
│ │
│ ✅ Add to PATH │
│ ✅ Set JAVA_HOME variable │
│ ✅ Associate .jar │
│ │
│ Install to: C:\Program Files\ │
│ Eclipse Adoptium\jdk-17.0.x.x\ │
│ │
│ [Install] │
└──────────────────────────────────────┘
Step 3: Verify the installation
Close all open terminals, then open a new PowerShell or CMD:
java -version
Expected result:
openjdk version "17.0.13" 2024-10-15
OpenJDK Runtime Environment Temurin-17.0.13+11 (build 17.0.13+11)
OpenJDK 64-Bit Server VM Temurin-17.0.13+11 (build 17.0.13+11, mixed mode, sharing)
javac -version
Expected result:
javac 17.0.13
Step 4: Verify JAVA_HOME
$env:JAVA_HOME
Expected result:
C:\Program Files\Eclipse Adoptium\jdk-17.0.13.11-hotspot
where.exe java
Expected result:
C:\Program Files\Eclipse Adoptium\jdk-17.0.13.11-hotspot\bin\java.exe
If JAVA_HOME is not set automatically
- Start Menu → type "environment variables"
- Click on "Edit the system environment variables"
- Click on "Environment Variables..."
- In System variables, click on New:
- Name:
JAVA_HOME - Value:
C:\Program Files\Eclipse Adoptium\jdk-17.0.13.11-hotspot
- Name:
- Find the
Pathvariable → Edit → New:%JAVA_HOME%\bin
- OK everywhere → Restart the terminal
🪟 Windows installation with Chocolatey (quick alternative)
If you have Chocolatey installed:
choco install temurin17
Verification:
java -version
javac -version
$env:JAVA_HOME
where.exe java
Chocolatey automatically configures JAVA_HOME and the PATH.
🪟 Windows installation with Scoop (quick alternative)
If you have Scoop installed:
scoop bucket add java
scoop install temurin17-jdk
Verification:
java -version
javac -version
$env:JAVA_HOME
where.exe java
Installation on macOS
🍎 macOS installation with Homebrew (Recommended)
Step 1: Install Homebrew (if not already done)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: Install the JDK 17
brew install --cask temurin@17
Step 3: Verify the installation
java -version
Expected result:
openjdk version "17.0.13" 2024-10-15
OpenJDK Runtime Environment Temurin-17.0.13+11 (build 17.0.13+11)
OpenJDK 64-Bit Server VM Temurin-17.0.13+11 (build 17.0.13+11, mixed mode)
javac -version
Expected result:
javac 17.0.13
Step 4: Verify the path and JAVA_HOME
which java
Expected result:
/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home/bin/java
/usr/libexec/java_home -v 17
Expected result:
/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
Step 5: Configure JAVA_HOME (permanent)
Open your shell profile file:
nano ~/.zshrc
Add at the end:
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
export PATH=$JAVA_HOME/bin:$PATH
Reload:
source ~/.zshrc
Verify:
echo $JAVA_HOME
Expected result:
/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
🍎 macOS installation with SDKMAN! (alternative)
Install SDKMAN!
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
List available Java 17 versions
sdk list java | grep tem
Result (example):
Temurin | | 17.0.13 | tem | installed | 17.0.13-tem
Install
sdk install java 17.0.13-tem
Verify
java -version
which java
echo $JAVA_HOME
Allows installing multiple versions of Java and easily switching:
sdk use java 17.0.13-tem # Use Java 17
sdk use java 21.0.5-tem # Switch to Java 21
sdk default java 17.0.13-tem # Set Java 17 as default
🍎 Manual macOS installation (direct download)
Step 1: Download
- Go to https://adoptium.net/
- Select macOS → aarch64 (Apple Silicon M1/M2/M3) or x64 (Intel)
- Download the
.pkgfile
Step 2: Install
Double-click the .pkg file and follow the wizard.
Step 3: Configure JAVA_HOME
echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 17)' >> ~/.zshrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
Step 4: Verify
java -version
javac -version
which java
echo $JAVA_HOME
Installation on Linux
🐧 Ubuntu / Debian (apt)
Step 1: Update packages
sudo apt update && sudo apt upgrade -y
Step 2: Install the JDK 17
Option A — OpenJDK from official repositories:
sudo apt install openjdk-17-jdk -y
Option B — Eclipse Temurin (recommended for uniformity):
sudo apt install -y wget apt-transport-https gpg
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public | \
gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/adoptium.gpg > /dev/null
echo "deb https://packages.adoptium.net/artifactory/deb $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/adoptium.list
sudo apt update
sudo apt install temurin-17-jdk -y
Step 3: Verify the installation
java -version
Expected result:
openjdk version "17.0.13" 2024-10-15
OpenJDK Runtime Environment Temurin-17.0.13+11 (build 17.0.13+11)
OpenJDK 64-Bit Server VM Temurin-17.0.13+11 (build 17.0.13+11, mixed mode, sharing)
javac -version
Expected result:
javac 17.0.13
Step 4: Verify the path
which java
Expected result:
/usr/bin/java
readlink -f $(which java)
Expected result (shows the real path):
/usr/lib/jvm/temurin-17-jdk-amd64/bin/java
Step 5: Configure JAVA_HOME
sudo nano /etc/environment
Add this line:
JAVA_HOME="/usr/lib/jvm/temurin-17-jdk-amd64"
Or for OpenJDK:
JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"
Reload:
source /etc/environment
echo $JAVA_HOME
echo 'export JAVA_HOME=/usr/lib/jvm/temurin-17-jdk-amd64' >> ~/.bashrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
If multiple versions of Java are installed
sudo update-alternatives --config java
This displays all installed versions and allows you to choose:
There are 2 choices for the alternative java.
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 2111 auto mode
1 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode
2 /usr/lib/jvm/java-21-openjdk-amd64/bin/java 2111 manual mode
Press <Enter> to keep the current choice[*] or type the selection number: 1
Same for javac:
sudo update-alternatives --config javac
🐧 Fedora / CentOS / RHEL (dnf/yum)
Fedora
sudo dnf install java-17-openjdk-devel -y
CentOS / RHEL
sudo yum install java-17-openjdk-devel -y
Verify
java -version
javac -version
which java
Configure JAVA_HOME
echo 'export JAVA_HOME=/usr/lib/jvm/java-17-openjdk' >> ~/.bashrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
echo $JAVA_HOME
Choose the active version
sudo alternatives --config java
sudo alternatives --config javac
🐧 Arch Linux / Manjaro (pacman)
🐧 Installation with SDKMAN! (all distributions)
Install SDKMAN!
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
Install Java 17
sdk list java | grep tem
sdk install java 17.0.13-tem
Verify
java -version
javac -version
which java
echo $JAVA_HOME
Manage multiple versions
sdk list java # See all available versions
sdk install java 21.0.5-tem # Install Java 21 additionally
sdk use java 17.0.13-tem # Use Java 17 for this session
sdk default java 17.0.13-tem # Java 17 as default
🐧 Manual installation (direct download)
Step 1: Download
cd /tmp
wget https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.13%2B11/OpenJDK17U-jdk_x64_linux_hotspot_17.0.13_11.tar.gz
Step 2: Extract
sudo mkdir -p /usr/lib/jvm
sudo tar -xzf OpenJDK17U-jdk_x64_linux_hotspot_17.0.13_11.tar.gz -C /usr/lib/jvm
Step 3: Configure
echo 'export JAVA_HOME=/usr/lib/jvm/jdk-17.0.13+11' >> ~/.bashrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
Step 4: Verify
java -version
javac -version
which java
echo $JAVA_HOME
Final verification (all OS)
Open a new terminal and run all these commands:
1. Java version
java -version
✅ Should display openjdk version "17.0.x"
2. Java compiler
javac -version
✅ Should display javac 17.0.x
3. Where is Java installed?
# macOS / Linux
which java
readlink -f $(which java) # real path (Linux)
# Windows PowerShell
where.exe java
4. Is JAVA_HOME set?
# macOS / Linux
echo $JAVA_HOME
# Windows PowerShell
$env:JAVA_HOME
# Windows CMD
echo %JAVA_HOME%
✅ Should display a path to JDK 17
5. Quick test — compile and run a program
Create a file Hello.java:
public class Hello {
public static void main(String[] args) {
System.out.println("Java " + System.getProperty("java.version") + " is working!");
System.out.println("JAVA_HOME = " + System.getProperty("java.home"));
}
}
Compile and run:
javac Hello.java
java Hello
Expected result:
Java 17.0.13 is working!
JAVA_HOME = /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
Clean up:
rm Hello.java Hello.class
Troubleshooting
❌ java is not recognized as a command
| Cause | Solution |
|---|---|
| Java is not installed | Follow the installation steps above |
| PATH not configured | Add JAVA_HOME/bin to PATH |
| Terminal not reloaded | Close and reopen the terminal |
Windows: Check that %JAVA_HOME%\bin is in the system PATH.
macOS/Linux: Check that your ~/.zshrc or ~/.bashrc contains:
export JAVA_HOME=...
export PATH=$JAVA_HOME/bin:$PATH
❌ Wrong Java version displayed
If java -version displays Java 8, 11, or 21 instead of 17:
Windows:
- Check the PATH: version 17 should appear before others
- Remove old versions from the PATH
macOS:
/usr/libexec/java_home -V # List all versions
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
java -version # Should now display 17
Linux:
sudo update-alternatives --config java # Choose version 17
sudo update-alternatives --config javac
❌ JAVA_HOME is not set
Windows:
- Start Menu → "environment variables"
- System variables → New
- Name:
JAVA_HOME, Value:C:\Program Files\Eclipse Adoptium\jdk-17.0.13.11-hotspot
macOS:
echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 17)' >> ~/.zshrc
source ~/.zshrc
Linux:
echo 'export JAVA_HOME=/usr/lib/jvm/temurin-17-jdk-amd64' >> ~/.bashrc
source ~/.bashrc
❌ Difference between java and javac
| Command | Role | Included in |
|---|---|---|
java | Run a compiled Java program | JRE and JDK |
javac | Compile .java source code into .class | JDK only |
If java works but not javac → you installed the JRE instead of the JDK. Reinstall the JDK.
❓ JDK vs JRE vs JVM — what's the difference?
┌─────────────────────────────────────┐
│ JDK │
│ (Java Development Kit) │
│ ┌────────────────────────────────┐ │
│ │ JRE │ │
│ │ (Java Runtime Environment) │ │
│ │ ┌──────────────────────────┐ │ │
│ │ │ JVM │ │ │
│ │ │ (Java Virtual Machine) │ │ │
│ │ │ Executes bytecode │ │ │
│ │ └──────────────────────────┘ │ │
│ │ + Standard libraries │ │
│ │ + java (run) │ │
│ └────────────────────────────────┘ │
│ + javac (compile) │
│ + jdb (debugger) │
│ + javadoc, jar, jshell... │
└─────────────────────────────────────┘
| Component | What it does | For whom |
|---|---|---|
| JVM | Executes Java bytecode | Everyone |
| JRE | JVM + libraries to run | End users |
| JDK | JRE + tools to develop (javac, jdb...) | Developers ← This is the one you need |
Validation checklist
Before moving on to the next TP (Maven Installation), check:
-
java -versiondisplays 17.0.x -
javac -versiondisplays 17.0.x -
which java(orwhere.exe java) returns a valid path -
echo $JAVA_HOME(or$env:JAVA_HOME) is set - The
Hello.javaprogram compiles and runs correctly
Next Step
Java 17 is installed! Now proceed to the Maven installation:
➡️ Next TP: Installation of Maven 3.9.x