Mastering the Art of Changing Java Versions in Ubuntu: A Comprehensive Guide
To change the default Java version in Ubuntu, you can follow these steps:
Check the installed Java versions on your system using the command:
1. Check the installed Java versions on your system using the command:
sudo update-alternatives --config java
This command will list all the installed Java versions on your system along with their paths.
2. Choose the version that you want to use as the default by typing the number next to it.
3. Press Enter to confirm your selection.
4. Check the version of Java that is currently set as the default by typing the command:
This command will display the version of Java that is currently set as the default on your system.
5. If you want to switch to a different version of Java, repeat the steps above.
6. You can also set the JAVA_HOME environment variable to point to the path of the Java version you want to use. To do this, open the /etc/environment file in a text editor and add the following line:
Replace “/path/to/java” with the path to the Java version you want to use.
7. Save the file and exit the text editor.
8. To apply the changes, run the following command:
This will reload the environment variables and apply the changes you made to the JAVA_HOME variable.
That’s it! You have successfully changed the default Java version in Ubuntu.