The post details on how to install Java on Ubuntu machines and commands used in the process.
1. Command to install Java on Ubuntu
Running the following command from terminal is how you can install java on Ubuntu machines
sudo apt-get install openjdk-version-jdk |
in place of version, type in the version number of java that you want to install
sudo apt-get install openjdk-8-jdk |
8 in place of version, if you are installing java 8.
sudo apt-get install openjdk-11-jdk |
11 in place of version, if you are installing java 11.
2. Checking java version
Once you have installed java on Ubuntu, the version can be checked by the following command
java -version |
3. Switching between versions of java
If in case you have two version of java installed on your machine, and you would like to switch between the versions, you can run the following command
$ sudo update-alternatives --config java |
Once you type this, you will be presented with all the versions available
[ * ] will be marked against the current version in use.
Press <enter> to keep the current choice[*], or type selection number:
If you want to keep the current version, just press enter.
If you wish to change the version, type the number mentioned for that version and hit enter.
Once done you can verify the changed version with the following command
java -version |
this should show the switched version of java.
4. Uninstalling java
Type in the following command
sudo apt-get remove openjdk-version* |
type in the version number, in place of version, like if you want to uninstall 8
sudo apt-get remove openjdk-8* |
Additional Info
Checkout the YouTube link on the same