Installing and Configuring JDK 11 on Linux Systems
Downloading JDK 11 from Oracle
Download the JDK 11 installation package (tar.gz or rpm) from the Oracle website and proceed with the installation.
Using tar.gz Package
wget https://download.oracle.com/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
tar -zxvf openjdk-11.0.2_linux-x64_bin.tar.gz
Setting Environment Variables
Configure the JAVA_HOME and PATH environment variibles:
export JAVA_HOME=/path/to/jdk-11.0.2
export PATH=$JAVA_HOME/bin:$PATH
Three Methods for Configuring Environment Variables
Method 1: Using the /etc/profile File
- Open a terminal and edit the
/etc/profilefile:
sudo vi /etc/profile
- Add the following content at the end of the file:
export JAVA_HOME=/usr/lib/jvm/jdk1.x.x # Modify based on your JDK installation path
export PATH=$PATH:$JAVA_HOME/bin
Note: Replace "jdk1.x.x" with your actual JDK version number.
-
Save and exit the file.
-
Apply the configuraton:
source /etc/profile
- Verify the configuration by checking the JDK version:
java -version
Method 2: Using the ~/.bashrc File
- Open a terminal and edit the
~/.bashrcfile:
vi ~/.bashrc
- Add the following content at the end of the file:
export JAVA_HOME=/usr/lib/jvm/jdk1.x.x # Modify based on your JDK installation path
export PATH=$PATH:$JAVA_HOME/bin
Note: Replace "jdk1.x.x" with your actual JDK version number.
-
Save and exit the file.
-
Apply the configuration:
source ~/.bashrc
- Verify the configuration by checking the JDK vertion:
java -version
Method 3: Using the /etc/environment File
- Open a terminal and edit the
/etc/environmentfile:
sudo vi /etc/environment
- Add the following content to the file:
JAVA_HOME="/usr/lib/jvm/jdk1.x.x" # Modify based on your JDK installation path
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$JAVA_HOME/bin"
Note: Replace "jdk1.x.x" with your actual JDK version number.
-
Save and exit the file.
-
Apply the connfiguration:
source /etc/environment
- Verify the configuration by checking the JDK version:
java -version
Conclusion
Using any of the three methods above, you can successfully configure JDK environment variables on a Linux system. Regardless of which method you choose, you must modify the paths according to your actual JDK installation. Once configured, you can directly use Java commands in the terminal and run Java applications smoothly.