Setting Up the Java Development Kit (JDK) on Your System
The process for installing and configuring the Java Development Kit (JDK) involves the following key actions.
1. Acquire the JDK Package
- Navigate to the official Oracle website or an alternative JDK provider such as Adoptium or Microsoft Build of OpenJDK.
- Select and download the appropriate JDK version for your operating system (e.g., Windows, macOS, Linux) and architecture (e.g., x64, ARM64).
- Official source: https://www.oracle.com/java/technologies/downloads/
2. Execute the Installer
- Launch the downloaded installer file. This is typically an
.exefile on Windows, a.dmgor.pkgfile on macOS, or a.tar.gzor.debarchive on Linux.
3. Complete the Installation
- Follow the prompts provided by the installation wizard. You may choose a custom installation directory if required.
4. Configure System Environment Variables
After installation, you must set environment variables so your system can locate Java commands. This primarily involves defining the JAVA_HOME variable and updating the PATH.
- Windows:
- Open System Properties > Advanced > Environment Variables.
- Under "System variables", click "New". Create a varibale named
JAVA_HOMEand set its value to the JDK installation path (e.g.,C:\Program Files\Java\jdk-21). - Find the
Pathvariable in the same list, select it, and click "Edit". Add a new entry:%JAVA_HOME%\bin.
- macOS / Linux:
Open a terminal and edit your shell configuration file (e.g.,
~/.bashrc,~/.zshrc, or~/.profile) using a text editor likenanoorvim.
Replaceexport JAVA_HOME=/usr/lib/jvm/jdk-21 export PATH=$JAVA_HOME/bin:$PATH/usr/lib/jvm/jdk-21with the actual path to your JDK installation.
5. Verify the Installation
Open a new command prompt or terminal window and run the following commands:
java -version
javac -version
These should output version information for the Java Runtime Environment (JRE) and the Java compiler, respectively, confirming a successful setup.
6. Manage Multiple JDK Versions (Optional)
If you have several JDK versions installed, you can configure the default version using system-specific tools:
- On Linux, you can use
update-alternatives --config java. - On macOS with Homebrew, you can use
jenvor setJAVA_HOMEdirectly.
7. Configure Integrated Development Environments (IDEs)
When using an IDE like IntelliJ IDEA, Eclipse, or VS Code, you need to point it to your JDK installation path within the IDE's project or global settings.
8. Apply Environment Changes
On macOS and Linux, you must either start a new terminal session or run the source command to load the updated configuration (e.g., source ~/.bashrc). On Windows, you may need to restart applications or the system for the new PATH to take full effect.