Setup Java in Linux: Quick Guide

Setting up a Java environment in Linux can be achieved by following these steps:

  1. Download Java JDK.
  2. Firstly, you need to download the latest Java JDK installation package from the official Oracle website, selecting the version that is compatible with your system (32-bit or 64-bit).
  3. Install Java JDK.
  4. Once the download is complete, use the following command to extract the installation package: tar -zxvf jdk-8u241-linux-x64.tar.gz
  5. Move the extracted file to the /usr/local directory: sudo mv jdk1.8.0_241 /usr/local/
  6. Set up the Java environment variables by editing the /etc/profile file, and add the following lines at the end:
    export JAVA_HOME=/usr/local/jdk1.8.0_241
    export PATH=$PATH:$JAVA_HOME/bin
    export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  7. Activate the configuration: source /etc/profile
  8. To verify if the installation was successful, use the command: java -version
  9. Set up the Java runtime environment.
  10. To run Java programs on Linux, you also need to install the Java Runtime Environment (JRE). You can install OpenJRE using the following command: sudo apt-get update sudo apt-get install default-jre
  11. Check if JRE is installed successfully: java -version.

By following these steps, you can successfully set up a Java environment on a Linux system and start developing and running Java programs.

bannerAds