Here’s a step-by-step guide to install Java 21 and set up your development environment:
Step 1: Download and Install Java 21
- Download JDK 21:
- Go to the official Oracle Java SE Downloads page or use Adoptium or OpenJDK for an open-source version.
- Download the JDK 21 version suitable for your system (Windows, macOS, or Linux).
- Install Java 21:
- Windows:
- Run the installer file and follow the prompts.
- macOS:
- Use the
.dmgpackage and follow the installation instructions.
- Use the
- Linux:
- Extract the
.tar.gzarchive or use a package manager likeaptoryumif supported by your Linux distribution. - Example for Ubuntu/Debian:
sudo apt update sudo apt install openjdk-21-jdk
- Extract the
- Windows:
Step 2: Set JAVA_HOME and PATH
Once Java is installed, set the JAVA_HOME and add the binary folder to your PATH.
Windows:
- Open System Properties:
- Press
Win + S, search for “Environment Variables,” and click it.
- Press
- Add a
JAVA_HOMEvariable:- Click New under System Variables.
- Variable Name:
JAVA_HOME - Variable Value: Path to the JDK installation directory (e.g.,
C:\Program Files\Java\jdk-21).
- Update the
PATHvariable:- Select the Path variable, click Edit, and add
%JAVA_HOME%\bin.
- Select the Path variable, click Edit, and add
macOS / Linux:
- Open your terminal and edit your shell configuration file (e.g.,
~/.bashrc,~/.zshrc, or~/.bash_profile):export JAVA_HOME=/path/to/java/jdk-21 export PATH=$JAVA_HOME/bin:$PATH - Apply the changes:
source ~/.bashrc # or source ~/.zshrc - Verify the installation:
java -version
Step 3: Set Up IntelliJ IDEA
- Download IntelliJ IDEA:
- Visit the IntelliJ IDEA website and download the latest version.
- Install the Ultimate Edition or the Community Edition, depending on your needs.
- Configure IntelliJ IDEA with Java 21:
- Open IntelliJ IDEA and go to File > Project Structure > SDKs.
- Click + to add a new JDK.
- Navigate to the Java 21 installation folder and select it.
- Set the project’s JDK version:
- Go to File > Project Structure > Modules and assign the JDK 21 to your project.
Step 4: Verify the Java Development Setup
- Create a sample application to test the setup:
- Create a new Java project in IntelliJ.
- Write a “Hello, World!” program:
public class Main { public static void main(String[] args) { System.out.println("Hello, World!"); } } - Run the program to ensure it works as expected.
- Confirm the Java version:
- Run the following in the terminal:
java -version - IntelliJ’s terminal should point to Java 21.
Optional: Tools to Enhance Development
- Maven/Gradle:
- Set up Maven or Gradle build tools for dependency management.
- Version Control:
- Install Git and set it up in IntelliJ.
- Extensions and Plugins:
- Install helpful IntelliJ plugins like Lombok, Checkstyle, JRebel, or a Database tool.
- Docker:
- If you’re working with containers, install Docker and configure IntelliJ’s Docker plugin.
You now have Java 21 and your development environment fully set up and configured!
