Setup Java in Linux: Quick Guide
Setting up a Java environment in Linux can be achieved by following these steps:
- Download Java JDK.
- 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).
- Install Java JDK.
- Once the download is complete, use the following command to extract the installation package: tar -zxvf jdk-8u241-linux-x64.tar.gz
- Move the extracted file to the /usr/local directory: sudo mv jdk1.8.0_241 /usr/local/
- 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 - Activate the configuration: source /etc/profile
- To verify if the installation was successful, use the command: java -version
- Set up the Java runtime environment.
- 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
- 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.