How to Install Java in Ubuntu
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
java -version
command. -
If any version is already present, upgrade to the desired version in the
apt
list. Otherwise, install a new package using the steps. -
Use the command
apt search openjdk
to get the list of available Java packages. -
Select the desired version and install using the
sudo apt install openjdk-8-jdk
command. This function provides the administrative privileges to get the work done in Linux-based systems. -
Additionally, if
apt
does not work, then atar
file 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/lib
location using the commandsudo mv jdk1.7.0_03/* /usr/lib/jvm
. -
Once
jdk
gets successfully installed or placed at the correct location, set theJAVA_HOME
environment variable. -
Use export command,
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
to set the correct Java version in the environment variable. -
There can be a possibility of more than one
jdk
present in the/lib
directory. In that case, select the appropriate path of your choice. -
Append the
JAVA_HOME
variable in thePATH
environment variable. Use theexport PATH=$PATH:$JAVA_HOME/bin
command to set the path variable. -
At the end, check the version you just installed using the command
java -version
.
Rashmi is a professional Software Developer with hands on over varied tech stack. She has been working on Java, Springboot, Microservices, Typescript, MySQL, Graphql and more. She loves to spread knowledge via her writings. She is keen taking up new things and adopt in her career.
LinkedIn