Installing Java on Windows, Linux, or MacOS

Java is a widely used programming language that powers numerous applications and platforms. Installing Java on your operating system is a crucial initial step to start developing Java applications. In this article, we will guide you through the installation process of Java on Windows, Linux, and MacOS.

Prerequisites

Before proceeding with the installation, make sure you have the following prerequisites:

  • Internet connectivity
  • Administrative access to your computer (for Windows and MacOS)
  • Terminal access (for Linux)

Installing Java on Windows

To install Java on Windows, follow these steps:

  1. Visit the official Java website at java.com.
  2. Click on the "Java Download" button, which will redirect you to the download page.
  3. On the download page, select the appropriate Java version for your system (32-bit or 64-bit). If unsure, choose the 32-bit version.
  4. Click on the "Agree and Start Free Download" button.
  5. Once the download is complete, locate the downloaded installation file (.exe) and double-click on it to start the installation.
  6. Follow the instructions presented by the Java installer to complete the installation process.
  7. After the installation, verify whether Java is properly installed by opening the command prompt and typing the following command:
java -version

If Java is installed correctly, the version information will be displayed.

Installing Java on Linux

Linux distributions often include OpenJDK, an open-source Java Development Kit, by default. To install OpenJDK or Oracle JDK on Linux, follow these steps:

Using Package Manager (Ubuntu/Debian-based)

  1. Open a terminal.
  2. Update the package information by running the following command:
sudo apt update
  1. To install OpenJDK, run the following command:
sudo apt install default-jdk
  1. To verify the installation, run the following command:
java -version

If installed correctly, the version information will be displayed.

Manual Installation

  1. Visit the official Oracle website at oracle.com.
  2. Scroll down to the "Java SE Development Kit 11" section and click on the "JDK Download" button.
  3. Accept the license agreement and download the appropriate JDK binary for your Linux distribution.
  4. Once the download is complete, open a terminal and navigate to the directory containing the downloaded file.
  5. Extract the downloaded archive by running the following command:
tar -xf <jdk_filename.tar.gz>
  1. Move the extracted directory to a desired location (e.g., /opt) by executing:
sudo mv <jdk_directory> /opt
  1. Set the environment variables by editing the .bashrc or .bash_profile file, located in your home directory, and adding the following lines:
export JAVA_HOME=/opt/<jdk_directory>
export PATH=$PATH:$JAVA_HOME/bin

Remember to replace <jdk_directory> with the actual name of the extracted JDK directory.

  1. To verify the installation, open a new terminal and run the following command:
java -version

If Java is correctly installed, the version information will be displayed.

Installing Java on MacOS

To install Java on macOS, you can follow these steps:

  1. Visit the official Oracle website at oracle.com.
  2. Scroll down to the "Java SE Development Kit 11" section and click on the "JDK Download" button.
  3. Accept the license agreement and download the appropriate JDK for macOS.
  4. Once the download is complete, locate the downloaded file (.dmg) and double-click on it to mount the disk image.
  5. Run the installer package (.pkg) that appears after mounting.
  6. Follow the instructions presented by the Java installer to complete the installation process.
  7. After the installation, verify whether Java is properly installed by opening the terminal and typing the following command:
java -version

If Java is installed correctly, the version information will be displayed.

Congratulations! You have successfully installed Java on your Windows, Linux, or macOS system. Now you are ready to start developing and running Java applications. Enjoy coding with Java!


noob to master © copyleft