Difference between revisions of "Linux Java"

From Ever changing code
Jump to navigation Jump to search
Line 7: Line 7:
  sudo apt-get install -y oracle-java8-installer
  sudo apt-get install -y oracle-java8-installer


= CentOS: Oracle Java 10.0.1 =
= Linux: Oracle Java 10.0.1 from tar.gz =
Go to Oracle and accept their license then you can download the file with cookie details provided.
Go to Oracle and accept their license then you can download the file with cookie details provided.



Revision as of 13:01, 26 May 2018

Ubuntu: Oracle Java 8 JDK - Java Development Kit - apt-get install method

Silent install Java 6/7/8/9 using WebUpd8 team's PPA

sudo apt-get install -y python-software-properties debconf-utils
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | sudo debconf-set-selections
sudo apt-get install -y oracle-java8-installer

Linux: Oracle Java 10.0.1 from tar.gz

Go to Oracle and accept their license then you can download the file with cookie details provided.

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://link_copied_from_site"
wget --no-check-certificate --no-cookies --header \
"Cookie: oraclelicense=accept-securebackup-cookie;" \
"http://download.oracle.com/otn-pub/java/jdk/10.0.1+10/fb4372174a714e6b8c52526dc134031e/serverjre-10.0.1_linux-x64_bin.tar.gz"
sudo tar -xzvf serverjre-10.0.1_linux-x64_bin.tar.gz -C /usr/local
sudo alternatives --install /usr/bin/java java /usr/local/jdk-10.0.1/bin/java 2
sudo alternatives --config java
sudo bash -c "echo export PATH=$PATH:/usr/local/jdk-10.0.1/bin >> /etc/environment" #PATH update
sudo bash -c "echo export JAVA_HOME=/usr/local/jdk-10.0.1 >> /etc/environment" #JAVA_HOME set up

Ubuntu: OpenJDK

You can use this Java open source installation when Oracle licensing causing limitations.

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-8-jdk -y

Ubuntu: Oracle Java 7 JDK - zip file install

This will treat how to install Oracle Java in Ubuntu. This method does not use any package management software. Use a link in the references section for other options.

Download the 32-bit or 64-bit Linux from "http://www.oracle.com/technetwork/java/javase/downloads/index.html" "compressed binary file" - it has a ".tar.gz" file extension.

Uncompress it

tar -xvf jdk-7u80-linux-x64.tar.gz (32-bit)
tar -xvf jdk-7u80-linux-x64.tar.gz (64-bit)

The JDK 7 package is extracted into ./jdk1.7.0_80 directory.

Now move the JDK 7 directory to /usr/lib

sudo mkdir -p /usr/lib/jvm
sudo mv ./jdk1.7.0_80 /usr/lib/jvm/

Optional: Environment variables

$ sudo vi /etc/environment      #add environment variables system wise, all users
PATH="search/paths:/usr/lib/jvm/jdk-oracle/bin"
JAVA_HOME=/usr/lib/jvm/jdk-oracle

Log log out and log back in, you should have Java available to you now.

Now run

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_80/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_80/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0_80/bin/javaws" 1

This will assign Oracle JDK a priority of 1, which means that installing other JDKs will replace it as the default. Be sure to use a higher priority if you want Oracle JDK to remain the default.

Correct the file ownership and the permissions of the executables:

sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root /usr/lib/jvm/jdk1.7.0_80

Run

sudo update-alternatives --config java

You will see output similar to the one below - choose the number of jdk1.7.0_80 - for example 3 in this list (unless you have have never installed Java installed in your computer in which case a sentence saying "There is nothing to configure" will appear):

$ sudo update-alternatives --config java

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

  Selection    Path                                  Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-oracle1/bin/java   1047      auto mode
  1            /usr/bin/gij-4.6                       1046      manual mode
  2            /usr/lib/jvm/java-6-oracle1/bin/java   1047      manual mode
  3            /usr/lib/jvm/jdk1.7.0_80/bin/java      1         manual mode

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

update-alternatives: using /usr/lib/jvm/jdk1.7.0_80/bin/java to provide /usr/bin/java (java) in manual mode

Repeat the above for:

sudo update-alternatives --config javac
sudo update-alternatives --config javaws

Verify

$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

Install another alternative manually

Before

  Selection    Path                  Priority   Status
------------------------------------------------------------
  0            /usr/bin/golang-go     10        auto mode
  1            /usr/bin/gccgo-go      5         manual mode
  2            /usr/bin/golang-go     10        manual mode

Installed manually unzipped GoLang into /usr/local/go but was not added to alternatives. Use command below to add it on:

sudo update-alternatives --install "/usr/bin/go" "go" "/usr/local/go/bin/go" 2

After

  Selection    Path                  Priority   Status
------------------------------------------------------------
* 0            /usr/bin/golang-go     10        auto mode
  1            /usr/bin/gccgo-go      5         manual mode
  2            /usr/bin/golang-go     10        manual mode
  3            /usr/local/go/bin/go   2         manual mode

Then run command to change go binary available in your shell

sudo update-alternatives --config go  #then select 3

When you run

$ go version #the version of go will be the one from /usr/local/go location.

References