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
![](https://rushiinfotech.in/wp-content/uploads/2023/09/01-copy-14-1024x54.png)
- Install OpenJDK 17:
Next, you can install OpenJDK 17 using the following command:
ubuntu@Rushi-InfoTech:~$ sudo apt install openjdk-17-jdk
![](https://rushiinfotech.in/wp-content/uploads/2023/09/01-copy-15-1024x80.png)
Please Confirm to install with yes “y“.
![](https://rushiinfotech.in/wp-content/uploads/2023/09/02-copy-11-1024x84.png)
- Verify Installation:
Once the installation process is complete, you can verify that Java 17 has been successfully installed:
ubuntu@Rushi-InfoTech:~$ java -version
![](https://rushiinfotech.in/wp-content/uploads/2023/09/03-copy-8-1024x118.png)
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
![](https://rushiinfotech.in/wp-content/uploads/2023/09/04-copy-7-1024x102.png)
- 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::"
![](https://rushiinfotech.in/wp-content/uploads/2023/09/05-copy-10-1024x65.png)
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
![](https://rushiinfotech.in/wp-content/uploads/2023/09/06-copy-7-1024x58.png)
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
![](https://rushiinfotech.in/wp-content/uploads/2023/09/07-copy-7-1024x85.png)
Now, Java 17 should be successfully installed and configured on your Ubuntu 20.04 system!
Any queries pls contact us
https://rushiinfotech.in/contact/