[Music]
hi everyone welcome back to our Channel
today we will show you how to install
Java on Ubuntu
24.4 we will cover both open jdk and
Oracle jdk so that you can choose the
best one for your needs before we start
let's quickly understand the difference
between these two open jdk stands for
open Java development kit this is free
and open source version of java it is
widely used and Main by Java Community
it is a default choice for most Linux
distributions Oracle jdk is the Oracle
official Java distribution which
includes additional performance
optimizations and Commercial features it
is often required for the Enterprise
applications now we know the difference
let's get started the first step is to
install all the available updates for
that log into your obuntu system open
the terminal run the command sudu
AP
update and
sudu app
upgrade i y h enter this command will
take 3 to 4 minutes depending upon your
internet speed
once all the updates are installed then
we will move to the open jdk
installation open jdk package and its
dependencies are available in the
default package depositories of open to
24.4 so it installation is
straightforward let me clear the screen
first and run the command sud do space
app space install space default hyphen
jdk space hyphen y
so this command will install open jdk 21
LTS which is officially supported
version for2
24.4 H
enter after the installation verify the
Java version with the
command Java space hyphen hyphen version
in the output we can clearly see we have
installed open zdk 21 in case you want
to install specific version of java
let's say Java 11 or Java 17 or Java 21
for that you need to run the
command sudu app
install open
jdk
hyphen let's say I I want to install
Java 11 then typee here 11 then hyphen
jdk hyphen y so this command will
install Java 11 if you want to install
Java 17 in place of
11 type 17 and for 21 in place of 17
type 21 let's assume I want to install
Java 11 as well so run this
command hit enter
if you need to install Oracle jdk then
first we need to download its debin
package from Oracle website in Google
search download Oracle
Java and hit
enter go to it official website
so at the time of creating this video
tutorial we have Java
23 look for the daan
package click on this
URL it will start downloading the Debian
package in your downloads folder once
the download is
completed go back to your
terminal go to the downloads folder
and if you do LS here you will get this
dein package in order to install this uh
Oracle zdk we need to run the
command sudu
appt install
do/ zdk hit enter
now if you run the command Java space
hyphen version you should see uh Java
version
23 great the output confirms that we
have installed Java 23 which is Oracle
jdk as you know we have installed
multiple Java versions on our obuntu
system now we will see how to configure
the default Java version for that we can
run the command update hyphen
Alternatives
command complete Command would be sud do
space update hyphen
Alternatives space hyphen hyphen config
space Java and hit
enter let's suppose I want to set this
Java 21 as my default Java for that
select the number so for Java 21 we need
to
select numeric 2
and H
enter and if you rerun the Java version
command you should see that default Java
version is open ZK 21 next set Java unor
home environment variable in order to
set this environment variable first we
need to find Java installation path if
you see the output of update alternative
space hyphen config Java command output
you will see the path of different Javas
so for 21 this would be the installation
path so copy this path till AMD
64 next addit the
file /c/
environment Define a variable
Java uncore home
equals
to and paste
that installation path you have just
copied now save this
file in order to make the changes into
the effect we need to Source this file
and the command Source space
/c/
environment verify that Java uncore home
is set correctly or not you can run the
command EOS space dollar Java uncore
home great output confirms that we have
a environment variable javore home whose
value is this
one before compiling any Java program
make sure both Java and Java
compilers are pointing to the same Java
version in order to change the Java
compiler
version Let run this command
again use Java C and hit
enter type two here and hit enter now
that Java is installed let's write a
sample Java program to test our setup
create a file with the name hello world.
Java
here is the sample code save and close
the
file now compile this program using the
command Java
C hello world.
Java now run the program with the
command Java
space world
great our program is executed
successfully I can see the
output that's it you have successfully
installed Java on your OB to2
24.4 and you have tested a sample hello
world program now you are ready to start
developing Java applications if you
found this tutorial helpful do not
forget to like subscribe and hit the
notification Bell for more Linux
tutorials let us know in the comments
which Java version you are using thanks
for watching watching see you in the
next video bye