Install Java on the RedHat Linux EC2 instance

- Launch Red-hat Linux EC2 instance
- SSH into your instance with Terminal to connect with the instance
- Run this command to become a Root User
$ sudo su - #To become root user4. Then Update the machine with this command
$ yum updat
5. Now check the java version, Linux machine comes with java installed.
$ java -version # to check java Version
$ yum remove java-1.8.0* #To remove Java version ( java-1.8.0* is version, you can replace with your version )6. if it’s not installed, you can install Java.
$ yum install java-11-openjdk-devel #To install java7. After installation, Then you have to set the Home path of java.
First, find your Java Path, then add it, To find use the below Command
$ find /usr/lib/jvm/java-11.0.17 | head -n 3
$ whereis java
$ ls -l /usr/bin/java
$ ls -l /etc/alternatives/java #You will get path on this command after running above commandsThis is my path, you will get your path, save the path for your next use.
/usr/lib/jvm/java-11-openjdk-11.0.17.0.8–2.el9_0.x86_64
You are in the root path, you need to switch to the homeopath to add the java path.
cd ~
Open this file, to add the path
$ vi .bash_profile # This is a file, where we will add path of javaafter adding the path, it will look like this.
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.17.0.8–2.el9_0.x86_64
PATH=$PATH:$JAVA_HOME:$HOME/bin
export PATHNow exit, by using the ‘exit’, then login to root by
$ exit
$ sudo su -now you can confirm the path by running this
$ echo $JAVA_HOMEit will output the latest path.
We are done with java. Thanks for reading my Article.