To install Java 17 on Ubuntu 20.04, you can use the OpenJDK package which is available from the default repositories. Here’s a step-by-step guide of “How to Install Java 17 in Ubuntu 20.04?”
- Update Package Repository:
First, you need to update the package repository to make sure you have the latest list of available packages.
ubuntu@Rushi-InfoTech:~$ sudo apt-get update
- Install OpenJDK 17:
Next, you can install OpenJDK 17 using the following command:
ubuntu@Rushi-InfoTech:~$ sudo apt install openjdk-17-jdk
Please Confirm to install with yes “y“.
- Verify Installation:
Once the installation process is complete, you can verify that Java 17 has been successfully installed:
ubuntu@Rushi-InfoTech:~$ java -version
You should see output indicating the version of Java you’ve just installed.
Similarly, you can check the javac
version (the Java compiler) with:
ubuntu@Rushi-InfoTech:~$ javac -version
- Setting Java 17 as the default (if you have multiple Java versions installed):
If you have more than one version of Java installed, you can set Java 17 as the default using theupdate-alternatives
command.
ubuntu@Rushi-InfoTech:~$ sudo update-alternatives --config java
And for the Java compiler:
ubuntu@Rushi-InfoTech:~$ sudo update-alternatives --config javac
Follow the on-screen prompts to select the version you want as the default.
- Setting JAVA_HOME:
It’s a good idea to set theJAVA_HOME
environment variable. First, find out the path where Java 17 is installed:
ubuntu@Rushi-InfoTech:~$ readlink -f /usr/bin/java | sed "s:bin/java::"
This will output the path to the Java installation. Now, you can set the JAVA_HOME
variable in your shell profile:
ubuntu@Rushi-InfoTech:~$ echo 'export JAVA_HOME=THE_PATH_FROM_ABOVE' >> ~/.bashrc
Make sure to replace THE_PATH_FROM_ABOVE
with the actual path you got from the previous command.
After adding this line, you can load the new settings:
ubuntu@Rushi-InfoTech:~$ source ~/.bashrc
Now, Java 17 should be successfully installed and configured on your Ubuntu 20.04 system!
Any queries pls contact us
https://rushiinfotech.in/contact/