dpcunningham / process-spinup-devenv-ionic4-ng-on-linux

Process: Spin Up a Development Environment for Ionic 4 (default Angular) Apps
0 stars 0 forks source link

install: Oracle JDK V8 (required for Android Studio builds) #15

Open dpcunningham opened 4 years ago

dpcunningham commented 4 years ago

Java and various JDKs/JREs are important prerequisites for Android Studio installs:

Per: JRE vs OpenJDK vs Oracle JDK

Before we go on seeing the process to install Java, let’s quickly understand the difference between JRE, OpenJDK and Oracle JDK.

  • JRE (Java Runtime Environment) is what you would need normally to run a Java-based application. This is all you need if you are not a programmer.
  • JDK (Java Development Kit) is what you need to if you have to do some do some programming or develop software related to Java.
  • OpenJDK is Open Source implementation of Java Development Kit while Oracle JDK is the official Oracle version of Java Development Kit. While OpenJDK is sufficient for most of the cases, some programs such Android Studio suggests using Oracle JDK to avoid UI/performance issue.

The "standard" process -- before 2019 -- was a typical Debian/Ubuntu apt-get cycle.

An article that distills the details of the typical approach is: Installing Using Unofficial PPA, which offers:

Install Java First

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default

Install Android Studio

sudo add-apt-repository ppa:paolorotolo/android-studio
sudo apt-get update
sudo apt-get install android-studio

All this is massively broken after April 2019 -- details below...

dpcunningham commented 4 years ago

Understand: Oracle's JDK Re-Licensing breaks FOSS installs from PPAs

It used to be that you could perform a standard Debian/Ubuntu apt-get install cycle for the JDK V8, as follows:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default

That wasn't good for Oracle. Larry's yacht needs barnacle scrapin', I s'pose...

The community-maintained PPAs, for example:

...can no longer be supported:

The Oracle JDK License has changed for releases starting April 16, 2019.

The new Oracle Technology Network License Agreement for Oracle Java SE is substantially different from prior Oracle JDK licenses. The new license permits certain uses, such as personal use and development use, at no cost -- but other uses authorized under prior Oracle JDK licenses may no longer be available. Please review the terms carefully before downloading and using this product. An FAQ is available here.

Oracle Java downloads now require logging in to an Oracle account to download Java updates, like the latest Oracle Java 8u211 / Java SE 8u212. Because of this I cannot update the PPA with the latest Java (and the old links were broken by Oracle).

For this reason, THIS PPA IS DISCONTINUED (unless I find some way around this limitation).


So now what?

The PPA notice above cites a link to a Oracle Java SE Licensing FAQ page:

Where can I get the latest releases of Java SE at no cost on or after April 16, 2019? Oracle provides the latest Java releases, made available in March and September each year, including quarterly performance, stability and security updates (in January, April, July and October) under an open source license at jdk.java.net. Also, Oracle provides updates; including Java 8, Java 11, and Java 12 of Oracle Java SE under the OTN License Agreement for Java SE at OTN.


Well, Oracle always plays nice, right?
So, if we follow that JDK link from above, we'll still have an easy install, right?

Sure! Let's see -- there are links to:

There look to be two options:

  1. A GNU licensed: Oracle Linux 6.1 x64 Java Development Kit (md5) 164 MB
    • which lets you d/l: openjdk-8u40-b25-linux-x64-10_feb_2015.tar.gz
  2. An Oracle licensed (that you must accept): Oracle Linux x64 Java Development Kit (md5) 164 MB
    • which lets you d/l: jdk_ri-8u40-b25-linux-x64-10_feb_2015.tar.gz

When you unpack the tarball(s), you find a README.html which links to online Java SE README Files

And that takes you down the following rabbit hole...

  1. README: Java™ Platform, Standard Edition 8 Development Kit
  2. System Requirements & Installation
  3. A new site!?!? Oracle Java Documentation

None of these guides have decent configuration information, especially for environment and path variables, and especially how to deal with existing java installations -- which is almost always going to be the case.

Learn from my pain, and follow the comment below... A New (post 2019) Approach to Oracle JDK V8 Installs

dpcunningham commented 4 years ago

A New (post 2019) Approach to Oracle JDK V8 Installs

From: How to Install Oracle JDK in Ubuntu 18 in 2020

install_oracle_jdk_ubuntu

In this short guide, I'll show you the new way of installation Oracle JDK: 8, 11 or 13 on Ubuntu 18 or Linux Mint 19 (and above). There are many articles describing the old steps which are not working anymore due to changes from Oracle. Below you can find the whole process - step by step.

Note 1: If you need OpedJDK then you can install it with command like: sudo apt-get install openjdk-8-jdk or by using SDKMAN - I prefer to use SDKMAN which gives many benefits like working with different versions and easy updates.

Note 2: Be sure that you read the Important Oracle JDK License Update before using Oracle JDK.

Step 1. Create Oracle account and download Oracle JDK

First in order to avoid confusion there are two Java downloads:

The second one is the one which has JDK and can be used for development. It's hosted on the Oracle website and needs Oracle account in order to download the JDK. Once the download is complete you can chose the Java version that you want to download - i.e. (or get the most recent version from the link above):

For Ubuntu/Linux Mint you need to download the .tar.gz file for your architecture: 32 or 64 Bits.

Step 2. Install Oracle JDK in /usr/lib/jvm

I check huge amount of articles trying to find what is the best place to install oracle JDK on Ubuntu. There are different choices so I decided to select: /usr/lib/jvm

which was the previous installation place for Oracle JDK 8.

Once the download is complete you can move the .tar.gz file to the folder of installation and extract it there:

cd Downloads
sudo mv jdk-8u231-linux-x64.tar.gz /usr/lib/jvm/
sudo tar xzvf jdk-8u231-linux-x64.tar.gz

This will install the JDK in folder - jdk1.8.0_231:

/usr/lib/jvm/jdk1.8.0_231

Step 3. Configure Java for update-alternatives (optional)

This step is needed in order to make newly installed Java visible for update-alternatives. What you need to do is:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_231/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_231/bin/javac 1

Now if there are more than one Java version you can manage then easily by:

sudo update-alternatives --config java

and then select the best Java for your machine(in the example below Oracle JDK is not installed):

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

Press <enter> to keep the current choice[*], or type selection number: 

Note: The number arguments at the end of the update-alternatives --install commands are a priority number.

The highest the number, the higher the priority. That means that the alternative with the highest number will be executed by default, unless we manually set which is the default.

Step 4. Set up variable JAVA_HOME (optional)

Many programs depends on environmental variable JAVA_HOME. So it's a good idea to set it up in order to avoid problems later. The setup of this variable for Debian based systems can be done by opening user profile settings:

sudo nano ~/.bashrc or sudo vi ~/.bashrc

Then you need to add somewhere near the bottom of the file:

export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_231
export PATH=$JAVA_HOME/bin:$PATH

Then you need to reset the terminal (by command source ~/.bashrc) or open new one and test the variable by echo:

source ~/.bashrc
echo $JAVA_HOME

With this last step the installation of Oracle JDK 8 on Ubuntu/Linux Mint/Debian is complete.

Bonus: The scripts for installation of Oracle JDK 11 or 13

    sudo mv jdk-11.0.5_linux-x64_bin.tar.gz /usr/lib/jvm/
    tar xzvf jdk-11.0.5_linux-x64_bin.tar.gz
    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.5/bin/java 11
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11.0.5/bin/javac 11
    sudo mv jdk-13.0.1_linux-x64_bin.tar.gz /usr/lib/jvm/
    tar xzvf jdk-13.0.1_linux-x64_bin.tar.gz
    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-13.0.1/bin/java 13
    sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-13.0.1/bin/javac 13

Resources

dpcunningham commented 4 years ago

Test the installation of the Oracle JDK V8

 1950  sudo cp jdk-8u231-linux-arm64-vfp-hflt.tar.gz /usr/lib/jvm
 1951  ls /usr/lib/jvm
 1952  cd /usr/lib/jvm/
 1953  ls
 1954  tar -xzvf jdk-8u231-linux-arm64-vfp-hflt.tar.gz 
 1955  ls
 1956  sudo tar -xzvf jdk-8u231-linux-arm64-vfp-hflt.tar.gz 
 1957  ls 
 1958  ls -l
 1959  ls /usr/lib/jvm/jdk1.8.0_231/
 1960  sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_231/bin/java 1
 1961  sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_231/bin/javac 1
 1962  sudo update-alternatives --config java  # Try choice 0 -- Open JDK
 1963  java --version
 1964  sudo update-alternatives --config java  # Try choice 1 -- Open JDK
 1965  java --version
 1966  sudo update-alternatives --config java  # Try choice 1 --  Oracle JDK V8
 1967  java --version  # Fails!  Binary incompatibility
 1968  sudo update-alternatives --config java
 1969  java --version
 1970  ls -l /usr/bin/java
 1971  /usr/lib/jvm/jdk1.8.0_231/bin/java --version # Binary not working !?!?!

On command 1967, I got a failure trying to run the new Oracle java. Some aort of binary incompatibility. The I realized: "Wait a sec -- that was an ARM 64 zip file! Jeez! Dawp!"

 1973  ls /usr/lib/jvm/jdk1.8.0_231
 1974  ls -l  /usr/lib/jvm/jdk1.8.0_231/bin
 1975  /usr/lib/jvm/jdk1.8.0_231/bin/java --version
 1976  ls
 1977  rm -Rf ./jdk1.8.0_231
 1978  sudo  rm -Rf ./jdk1.8.0_231
 1979  ls
 1980  sudo rm jdk-8u231-linux-arm64-vfp-hflt.tar.gz 

Let's find & install the x64 one for this Linux Mint 19.

 1981  sudo cp /home/dpc/dpc.data/local.FS/lfs.00-Scratch/install.oracle.jdkv8/jdk-8u231-linux-x64.tar.gz .
 1982  ls 
 1983  sudo tar -xzvf jdk-8u231-linux-x64.tar.gz 
 1984  sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_231/bin/java 1
 1985  sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_231/bin/javac 1
 1986  sudo update-alternatives --config java # Try choice 0 -- Open JDK
 1987  java --version
 1988  sudo update-alternatives --config java # Try choice 1 -- Open JDK
 1989  java --version
 1990  sudo update-alternatives --config java # Try choice 0 -- Oracle JDK V8

This is where I discover fuckin' Oracle JDK uses non-standard CL args -- seriously?

 1991  java --version   # ERROR!
 1992  java -v              # ERROR!
 1993  java --version   # You can't be THAT stoopid, right?  No, you can be!
 1994  java                  # Is ANYTHING working?
 1995  java -version    # Seriously?  It's like dealing with a toddler.  Fuck you, Ellison!
dpcunningham commented 4 years ago

Confirm Status of the Oracle JDK V8 Required for Ionic Android Builds

$ sudo update-alternatives --config java 
[sudo] password for dpc:                  
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                         Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1101      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1101      manual mode
* 2            /usr/lib/jvm/jdk1.8.0_231/bin/java            1         manual mode

Press <enter> to keep the current choice[*], or type selection number:         

$ which java
/usr/bin/java

$ ls -l  /usr/bin/java
lrwxrwxrwx 1 root root 22 Apr 13  2019 /usr/bin/java -> /etc/alternatives/java

$ java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

$ more /etc/profile.d/java_home.sh
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_231
export PATH=$JAVA_HOME/bin:$PATH

$ echo $JAVA_HOME
/usr/lib/jvm/jdk1.8.0_231
dpcunningham commented 4 years ago

Reference Links: