go to  ForumEasy.com   
JavaPro  
 
 
   Home  |  MyForum  |  FAQ  |  Archive    You are not logged in. [Login] or [Register]  
Forum Home » Amazon AWS » Install JAVA JDK on AWS EC2 instance
Email To Friend  |   Set Alert To This Topic Rewarding Points Availabe: 0 (What's this) New Topic  |   Post Reply
Author Topic: Install JAVA JDK on AWS EC2 instance
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 10/12/2011 07:58:43 PM    Edit  |   Quote  |   Report 
Install JAVA JDK on AWS EC2 instance
Download a JDK RPM from http://download.java.net/jdk6/. Look for "RPM" under "Linux". Copy the link address to "jdk-6u29-ea-bin-b08-linux-i586-23_sep_2011-rpm.bin" and then use curl.

# mkdir /usr/local/java
# cd /usr/local/java
# curl http://download.java.net/jdk6/6u29/promoted/b08/binaries/
jdk-6u29-ea-bin-b08-linux-i586-23_sep_2011-rpm.bin > jdk-rpm.bin


Then follow the instructions on http://alwajdi.blogspot.com/2007/12/how-to-install-snns-jdk-in-fedora-8.html to install the downloaded JDK.
# chmod 755 jdk-rpm.bin
# ./jdk-rpm.bin 
# /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_29/bin/java 100
# /usr/sbin/alternatives --install /usr/bin/jar jar /usr/java/jdk1.6.0_29/bin/jar 100
# /usr/sbin/alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_29/bin/javac 100
# /usr/sbin/alternatives --config java


Type the following command to verify the exact path to which java executable under UNIX / Linux:
# which java
/usr/bin/java

Also to make sure the version is correct:
# java -version
java version "1.6.0_29-ea"
Java(TM) SE Runtime Environment (build 1.6.0_29-ea-b08)
Java HotSpot(TM) Client VM (build 20.4-b01, mixed mode, sharing)

 Profile | Reply Points Earned: 0
Linux
member
offline   
 
posts: 120
joined: 01/24/2011
from: San Jose, CA
  posted on: 10/12/2011 08:54:23 PM    Edit  |   Quote  |   Report 
Set environment variable JAVA_HOME under Linux
There are three ways.

1). Set for current environment
$ export JAVA_HOME=/usr/java/jdk1.6.0_29


Type the following to verify
$ echo $JAVA_HOME
/usr/java/jdk1.6.0_29


2). Set for single user
Login to your account and open .bash_profile or .bashrc file
$ vi ~/.bash_profile

Type the following:
export JAVA_HOME=/usr/java/jdk1.6.0_29

Save and close the file. Just logout and login back to see the change.
$ echo $JAVA_HOME
/usr/java/jdk1.6.0_29


3). Set for all users
Login as root user and setup the global config in /etc/profile OR /etc/bash.bashrc file for all users:
# vi /etc/profile

Type the following:
export JAVA_HOME=/usr/java/jdk1.6.0_29


Save and close the file.
 Profile | Reply Points Earned: 0
AwsEC2
member
offline   
 
posts: 39
joined: 08/28/2012
from: CA
  posted on: 08/28/2012 02:21:51 PM    Edit  |   Quote  |   Report 
Install JDK 64-bit version
Download a JDK RPM from http://www.oracle.com/technetwork/java/javase/downloads/index.html. Look for "linux-x64-rpm" and download JDK 64-bit version from http://download.oracle.com/otn-pub/java/jdk/6u34-b04/jdk-6u34-linux-x64-rpm.bin

Step 1). Make the folder available
# mkdir /usr/local/java
# cd /usr/local
# chmod 777 java


Step 2). Upload the downloaded JDK by WinSCP

Copy jdk-6u34-linux-x64-rpm.bin onto /usr/local/java/

Step 3). Install JDK

Then follow the instructions on http://alwajdi.blogspot.com/2007/12/how-to-install-snns-jdk-in-fedora-8.html to install the downloaded JDK.

# chmod 755 jdk-6u34-linux-x64-rpm.bin
# ./jdk-6u34-linux-x64-rpm.bin


Note: The installed JDK jdk1.6.0_34 will be under /usr/java/

Step 4). Override the default JDK link

The AWS-Linux instance comes with a built-in JDK. You can find it out by:

$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.3) (amazon-52.1.11.3.45.amzn1-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)


Which is OpenJDK 64-Bit Server VM.

Where does it locate? You can find it out by:

$ which java
/user/bin/java


How to override this default built-in JDK? You can do it by alternatives:

alternatives --install <link> <name> <path> <priority>


# /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_34/bin/java 100
# /usr/sbin/alternatives --install /usr/bin/jar jar /usr/java/jdk1.6.0_34/bin/jar 100
# /usr/sbin/alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_34/bin/javac 100
# /usr/sbin/alternatives --config java


Step 5). Just make sure everything is correct
# java -version
java version "1.6.0_34"
Java(TM) SE Runtime Environment (build 1.6.0_34-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.9-b04, mixed mode)


 Profile | Reply Points Earned: 0
AwsEC2
member
offline   
 
posts: 39
joined: 08/28/2012
from: CA
  posted on: 08/28/2012 06:59:03 PM    Edit  |   Quote  |   Report 
Set environment variable JAVA_HOME
After changing any environment settings, you have to log off to let the changes take effect.

Quick notes on vi:

1) Start vi
vi <filename>

2) Browse
:$ -- Last line
:0 -- First line

3) Insert
i <changes> Esc

4) Copy-Paste
yy -- copy current line
yNy -- copy N lines
p -- paste

5) Search
/<str> -- search for <str>

6) Exit vi:
:x -- to eXit (save+quit)
:q -- to quit
:q! -- to quit without save


 Profile | Reply Points Earned: 0
AwsEC2
member
offline   
 
posts: 39
joined: 08/28/2012
from: CA
  posted on: 04/20/2016 11:33:47 PM    Edit  |   Quote  |   Report 
Upgrade JDK to JDK 7u79



Download JDK package

There are two packages available for Linux: .rpm and .gz. If you download the .rpm package, you can unwrap it with:

rpm -i jdk-7u79-linux-x64.rpm
[/cpde]

The following is to download .gz package directly unto the linux box.

[code]

# cd /opt

# wget --no-cookies --no-check-certificate 
      --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; 
      oraclelicense=accept-securebackup-cookie" 
      "http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz"

# tar xzf jdk-7u79-linux-i586.tar.gz



Now you should see an extra folder 'jdk1.7.0_79' under /opt/



Stop old services

The previous link can be found as:
# which java
/usr/bin/java



/usr/bin/java  --> /etc/alternatives/java --> /usr/java/jdk1.6.0_34/bin/java


Now first stop all java apps which are running on this jre before we can install the new one.


# /env/tomcat/apache-tomcat-6.0.35/bin/shutdown.sh
# /etc/init.d/httpd stop
 




Install JDK Linkage


# /usr/sbin/alternatives --install /usr/bin/java java /opt/jdk1.7.0_79/bin/java 100
# /usr/sbin/alternatives --install /usr/bin/jar jar /opt/jdk1.7.0_79/bin/jar 100
# /usr/sbin/alternatives --install /usr/bin/javac javac /opt/jdk1.7.0_79/bin/javac 100
# /usr/sbin/alternatives --config java


There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  1           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
 + 2           /usr/java/jdk1.6.0_34/bin/java
   3           /opt/jdk1.7.0_79/bin/java

Enter to keep the current selection[+], or type selection number: 3




You can verify the version by:


# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)



Environment Settings


# vi /etc/profile

i    -- insert

export JAVA_HOME=/opt/jdk1.7.0_79

Esc  -- exit insert mode
dd   -- delete current line

export JAVA_HOME=/usr/java/jdk1.7.0_79

:x   -- save and exit vi




Finally, log off to let the changes take effect.

 Profile | Reply Points Earned: 0

 
Powered by ForumEasy © 2003-2005, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.