How to Install Java 21 and Set Up Your Development Environment

Here’s a step-by-step guide to install Java 21 and set up your development environment:

### Step 1: **Download and Install Java 21**
1. **Download JDK 21**:
– Go to the official [Oracle Java SE Downloads page](https://www.oracle.com/java/technologies/javase-downloads.html) or use [Adoptium](https://adoptium.net/) or OpenJDK for an open-source version.
– Download the JDK 21 version suitable for your system (Windows, macOS, or Linux).

2. **Install Java 21**:
– **Windows**:
– Run the installer file and follow the prompts.

– **macOS**:
– Use the `.dmg` package and follow the installation instructions.

– **Linux**:
– Extract the `.tar.gz` archive or use a package manager like `apt` or `yum` if supported by your Linux distribution.
– Example for Ubuntu/Debian:

“`bash
sudo apt update
sudo apt install openjdk-21-jdk
“`

### Step 2: **Set JAVA_HOME and PATH**

Once Java is installed, set the `JAVA_HOME` and add the binary folder to your `PATH`.

#### **Windows:**
1. Open **System Properties**:
– Press `Win + S`, search for “Environment Variables,” and click it.

2. Add a `JAVA_HOME` variable:
– 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`).

3. Update the `PATH` variable:
– Select the **Path** variable, click **Edit**, and add `%JAVA_HOME%\bin`.

#### **macOS / Linux:**
1. Open your terminal and edit your shell configuration file (e.g., `~/.bashrc`, `~/.zshrc`, or `~/.bash_profile`):

“`bash
export JAVA_HOME=/path/to/java/jdk-21
export PATH=$JAVA_HOME/bin:$PATH
“`

2. Apply the changes:

“`bash
source ~/.bashrc
# or
source ~/.zshrc
“`

3. Verify the installation:

“`bash
java -version
“`

### Step 3: **Set Up IntelliJ IDEA**
1. **Download IntelliJ IDEA**:
– Visit the [IntelliJ IDEA website](https://www.jetbrains.com/idea/) and download the latest version.
– Install the Ultimate Edition or the Community Edition, depending on your needs.

2. **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.

3. 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**
1. Create a sample application to test the setup:
– Create a new Java project in IntelliJ.
– Write a “Hello, World!” program:

“`java
public class Main {
public static void main(String[] args) {
System.out.println(“Hello, World!”);
}
}
“`
– Run the program to ensure it works as expected.

2. Confirm the Java version:
– Run the following in the terminal:

“`bash
java -version
“`

3. IntelliJ’s terminal should point to Java 21.

### Optional: Tools to Enhance Development
1. **Maven/Gradle**:
– Set up Maven or Gradle build tools for dependency management.
2. **Version Control**:
– Install Git and set it up in IntelliJ.
3. **Extensions and Plugins**:
– Install helpful IntelliJ plugins like Lombok, Checkstyle, JRebel, or a Database tool.
4. **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!

Leave a Reply