How to install Java on your Amazon EC2 instance?

Amazon EC2 dashboard
> chmod 400 mypemfile.pem
> ssh -i mypemfile.pem ec2-user@xx.x.xx.xxx
[ec2-user@ip-xxx-xx-xx-xxxx ~]$ sudo su
[ec2-user@ip-xxx-xx-xx-xxxx ~]$ yum update
[ec2-user@ip-xxx-xx-xx-xxxx ~]$ java -version
[ec2-user@ip-xxx-xx-xx-xxxx /]$ cd ..
[ec2-user@ip-xxx-xx-xx-xxxx /]$ cd ..
[ec2-user@ip-xxx-xx-xx-xxxx lib]$ chmod u=rwx,g=rwx,o=rwx jvm
> sudo scp -i mypemfile.pem jdk-16.0.2_linux-x64_bin.tar.gz ec2-user@x.xx.xxx.xxx:/usr/lib/jvm/
[ec2-user@ip-xxx-xx-xx-xxxx jvm]$ tar zxvf jdk-16.0.2_linux-x64_bin.tar.gz
[ec2-user@ip-xxx-xx-xx-xxxx jvm]$ sudo su[ec2-user@ip-xxx-xx-xx-xxxx jvm]$ nano /etc/environment
PATH= “/usr/lib/jvm/jdk-jdk-16.0.2/bin”JAVA_HOME= “/usr/lib/jvm/jdk-jdk-16.0.2”
[ec2-user@ip-xxx-xx-xx-xxxx jvm]$ update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-16.0.2/bin/java" 0[ec2-user@ip-xxx-xx-xx-xxxx jvm]$ update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-16.0.2/bin/javac" 0

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store