Install Java in Ubuntu
Rashmi Patidar Oct 12, 2021 Jul 24, 2021
Ubuntu is an open-source Operating System based on the Debian for Linux Distribution systems. The powerful OS is available in different versions and is available for free. The system is compatible enough to be installed in a virtual machine.
apt, acronym for
Advanced Packaging Tool, is a package library that provides additional functionality. The library can handle software and function downloads; it can even upgrade the existing Ubuntu system. The tool is available as a command and allows the installation and removal of packages.
The steps to install and start Java in the Ubuntu environment are listed below.
Check the existing version of Java present in the system using the
If any version is already present, upgrade to the desired version in the
aptlist. Otherwise, install a new package using the steps.
Use the command
apt search openjdkto get the list of available Java packages.
Select the desired version and install using the
sudo apt install openjdk-8-jdkcommand. This function provides the administrative privileges to get the work done in Linux-based systems.
aptdoes not work, then a
tarfile can be downloaded manually and extracted using the command.
The command unzips the downloaded file,
tar -xvf ~/Downloads/jdk-7u3-linux-i586.tar.gz.
Move the newly created directory to the
/usr/liblocation using the command
sudo mv jdk1.7.0_03/* /usr/lib/jvm.
jdkgets successfully installed or placed at the correct location, set the
Use export command,
export JAVA_HOME=/usr/lib/jvm/java-8-openjdkto set the correct Java version in the environment variable.
There can be a possibility of more than one
jdkpresent in the
/libdirectory. In that case, select the appropriate path of your choice.
JAVA_HOMEvariable in the
PATHenvironment variable. Use the
export PATH=$PATH:$JAVA_HOME/bincommand to set the path variable.
At the end, check the version you just installed using the command