Difference between revisions of "JDK setup"

(ORACLE JVM manual installation (debian))
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:Linux]]
 +
[[Category:Development]]
 +
 +
 
“Java” is one of the most popular and common language in this world.  
 
“Java” is one of the most popular and common language in this world.  
  
 
It's everywhere, and you need some library to execute these programs.
 
It's everywhere, and you need some library to execute these programs.
  
==Get Java==
+
 
 +
 
 +
=Get Java=
 +
 
 
2 versions of Java are available:
 
2 versions of Java are available:
* '''JRE''' as Java Runtime Environment. For end-users
 
* '''JDK''' as Java Devolpment Kit. For developers and application servers 
 
  
Download JRE: https://java.com/getjava‎
+
* '''JRE''' as Java Runtime Environment. For end-users. Download JRE: https://java.com/getjava‎
 +
* '''JDK''' as Java Devolpment Kit. For developers and application servers.
 +
 
 +
The JDK includes the corresponding JRE. Download JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html
 +
 
 +
You need to install the JDK on your development station & servers.
 +
 
 +
 
 +
 
 +
 
 +
=Windows installation=
 +
 
 +
 
 +
1. Create a new environment variable
 +
 
 +
* Name:  JAVA_HOME
 +
* Value:    path to your JDK installation (C:\Program Files\java\jdk1.7.0_45)
 +
 +
 
 +
2. Update the PATH
 +
 
 +
* Add following sequence to the end of the PATH variable:
 +
<syntaxhighlight lang="bash">
 +
      > %JAVA_HOME%\bin
 +
</syntaxhighlight>
 +
 +
 
 +
3. Check installation
 +
 
 +
* Open a new terminal console [Run -> "cmd"]
 +
* Run:  java -version
 +
 
 +
 +
 
 +
=Linux installation=
 +
 
 +
On a server, I advise you to put the JDK instead of the JRE. Many services requires the JDK such as JMX.
 +
 
 +
While on Windows ORACLE java is almost the only JVM available, on Linux you can choose your JVM vendor: OpenJDK, ORACLE, ....
 +
I advise you to use the official ORACLE library, instead of the OpenSource OpenJDK due to stability issues and JavaFX2 compability.
 +
 
 +
 
 +
==ORACLE JVM automatic installation (ubuntu)==
 +
 
 +
This is for Ubuntu based distributions only.
 +
 
 +
 
 +
Add a new repository (automatic):
 +
 
 +
<syntaxhighlight lang="bash">
 +
add-apt-repository ppa:webupd8team/java
 +
</syntaxhighlight>
 +
 
 +
 
 +
 
 +
Add a new repository (manual):
 +
 
 +
<syntaxhighlight lang="bash">
 +
vim /etc/apt/sources.list
 +
 
 +
## Java repository
 +
deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main
 +
 
 +
 
 +
 
 +
### Install repo key
 +
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
 +
</syntaxhighlight>
 +
 
  
Download JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html
 
  
==Windows installation==
 
  
==Linux installation==
+
Install ORACLE JDK packages:
 +
 
 +
<syntaxhighlight lang="bash">
 +
apt-get update
 +
# Oracle JDK 8 - most of the production applications
 +
apt-get install oracle-java8-installer
 +
 
 +
# OpenJDK 11 - new applications are being develop with it
 +
# /!\ Careful: the ORACLE version is not free, you must pay to use it.
 +
apt install openjdk-11-jdk
 +
apt install openjdk-11-jre
 +
 
 +
</syntaxhighlight>
 +
 
 +
This will download the latest JDK, install it automatically and set the new JVM as the default one.
 +
 
  
On a server, I advised you to put the JDK (Developer Kit) instead of the JRE (Run-time
 
only). The JDK include the JRE
 
 
 I also advised you to use the official ORACLE library, instead of the OpenSource
 
(OpenJDK).
 
Automatic install (Ubuntu)
 
On Ubuntu based distributions you can do the following:
 
# add-apt-repository ppa:webupd8team/java
 
# apt-get update
 
# apt-get install oracle-java7-installer oracle-jdk7-installer
 
 
To remove the repository:
 
To remove the repository:
# apt-add-repository --remove ppa:webup8team/java
+
 
Guillaume Diaz
+
<syntaxhighlight lang="bash">
Page 5 / 30
+
apt-add-repository --remove ppa:webup8team/java
version 1.8Continuous Integration Platform # Linux
+
</syntaxhighlight>
Manual install (debian)
+
 
You've to retrieve the JDK / JRE from the sun website
+
==Choose default JVM engine==
http://www.oracle.com/technetwork/java/javase/downloads/index.html
+
 
Download Oracle JDK
+
 
Download link: http://download.oracle.com/otn-pub/java/jdk/7u9-b05/jdk-7u9-linux-
+
===Register new JVM===
x64.tar.gz
+
 
# wget -c --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F"
+
To register a new JVM you need to know the path to it:
"<DOWNLOAD_URL>" --output-document="<TARGET_FILE_NAME>"
+
 
Installation
+
<syntaxhighlight lang="bash">
# tar -xzvf jdk-7u9-linux-x64.tar.gz
+
update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_45/bin/java 1065
# mv jdk1.7.* /usr/lib/jvm
+
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_45/bin/javac 1065
# cd /usr/lib/jvm
+
update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.0_45/bin/jar 1065
Adjust symlink
+
update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.7.0_45/bin/javaws 1065
# rm /usr/lib/jvm/default-java
+
</syntaxhighlight>
# ln -s /usr/lib/jvm/jdk1.7.0_17/ /usr/lib/jvm/default-java
+
 
Perform update
+
 
# update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_09/bin/java 1065
+
===Choose default JVM===
# update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_09/bin/javac 1065
+
 
# update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.0_09/bin/jar 1065
+
<syntaxhighlight lang="bash">
# update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.7.0_09/bin/javaws 1065
+
update-alternatives --config java
Choose system version
+
update-alternatives --config javac
# update-alternatives --config java
+
update-alternatives --config javaws
Check result
+
update-alternatives --config jar
# java -version
+
</syntaxhighlight>
Update environment
+
 
You need to add an environment variable:
+
* Check result
# vim /etc/profile
+
 
Ubuntu:
+
<syntaxhighlight lang="bash">
# vim /etc/environment
+
java -version
export JAVA_HOME="/usr/lib/jvm/jdk1.7.0_09"
+
</syntaxhighlight>
if [ "`id -u`" -eq 0 ]; then
+
 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$JAVA_HOME/bin"
+
 
else
+
 
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:$JAVA_HOME/bin"
+
===Environment variable JAVA_HOME===
fi
+
 
export PATH
+
 
Guillaume Diaz
+
You need to add an environment variable JAVA_HOME, if it does not already exist:
Page 6 / 30
+
* Debian
version 1.8Continuous Integration Platform # Linux
+
 
Reminders
+
<syntaxhighlight lang="bash">
Don't forget to adjust the JAVA related services:
+
vim /etc/profile
Tomcat
+
</syntaxhighlight>
/etc/default/tomcat7
+
 
Eclipse IDE
+
* Ubuntu
eclipse.ini
+
 
Jenkins
+
<syntaxhighlight lang="bash">
etc.
+
vim /etc/environment
Java # OpenJdk
+
</syntaxhighlight>
It’s always good to setup OpenJDK as well, especially for the old version as there is more updates.
+
 
# apt-get install openjdk-6-jdk
+
==OpenJdk==
 +
 
 +
It’s always good to setup OpenJDK as well, especially for the old versions as there is more updates than the ORACLE version.
 +
 
 +
<syntaxhighlight lang="bash">
 +
apt-get install openjdk-6-jdk openjdk-7-jdk
 +
</syntaxhighlight>
 +
 
 +
 
 +
==Choose default java version==
 +
 
 +
 
 +
<syntaxhighlight lang="bash">
 +
update-alternatives --config java
 +
update-alternatives --config javac
 +
update-alternatives --config javaws
 +
update-alternatives --config jar
 +
</syntaxhighlight>
 +
 
 +
 
 +
==Reminders==
 +
 
 +
 
 +
Don't forget to adjust the JAVA_HOME in all JAVA related services:
 +
* Tomcat: /etc/default/tomcat7
 +
* Eclipse IDE: eclipse.ini
 +
* Jenkins
 +
* etc.

Latest revision as of 17:45, 28 March 2019


“Java” is one of the most popular and common language in this world.

It's everywhere, and you need some library to execute these programs.


Get Java

2 versions of Java are available:

  • JRE as Java Runtime Environment. For end-users. Download JRE: https://java.com/getjava‎
  • JDK as Java Devolpment Kit. For developers and application servers.

The JDK includes the corresponding JRE. Download JDK: http://www.oracle.com/technetwork/java/javase/downloads/index.html

You need to install the JDK on your development station & servers.



Windows installation

1. Create a new environment variable

  • Name: JAVA_HOME
  • Value: path to your JDK installation (C:\Program Files\java\jdk1.7.0_45)


2. Update the PATH

  • Add following sequence to the end of the PATH variable:
      > %JAVA_HOME%\bin


3. Check installation

  • Open a new terminal console [Run -> "cmd"]
  • Run: java -version


Linux installation

On a server, I advise you to put the JDK instead of the JRE. Many services requires the JDK such as JMX.

While on Windows ORACLE java is almost the only JVM available, on Linux you can choose your JVM vendor: OpenJDK, ORACLE, .... I advise you to use the official ORACLE library, instead of the OpenSource OpenJDK due to stability issues and JavaFX2 compability.


ORACLE JVM automatic installation (ubuntu)

This is for Ubuntu based distributions only.


Add a new repository (automatic):

add-apt-repository ppa:webupd8team/java


Add a new repository (manual):

vim /etc/apt/sources.list

## Java repository
deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main



### Install repo key
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886



Install ORACLE JDK packages:

apt-get update
# Oracle JDK 8 - most of the production applications
apt-get install oracle-java8-installer

# OpenJDK 11 - new applications are being develop with it
# /!\ Careful: the ORACLE version is not free, you must pay to use it.
apt install openjdk-11-jdk
apt install openjdk-11-jre

This will download the latest JDK, install it automatically and set the new JVM as the default one.


To remove the repository:

apt-add-repository --remove ppa:webup8team/java

Choose default JVM engine

Register new JVM

To register a new JVM you need to know the path to it:

update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_45/bin/java 1065
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_45/bin/javac 1065
update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.0_45/bin/jar 1065
update-alternatives --install /usr/bin/javaws javaws /usr/lib/jvm/jdk1.7.0_45/bin/javaws 1065


Choose default JVM

update-alternatives --config java
update-alternatives --config javac
update-alternatives --config javaws
update-alternatives --config jar
  • Check result
java -version


Environment variable JAVA_HOME

You need to add an environment variable JAVA_HOME, if it does not already exist:

  • Debian
vim /etc/profile
  • Ubuntu
vim /etc/environment

OpenJdk

It’s always good to setup OpenJDK as well, especially for the old versions as there is more updates than the ORACLE version.

apt-get install openjdk-6-jdk openjdk-7-jdk


Choose default java version

update-alternatives --config java
update-alternatives --config javac
update-alternatives --config javaws
update-alternatives --config jar


Reminders

Don't forget to adjust the JAVA_HOME in all JAVA related services:

  • Tomcat: /etc/default/tomcat7
  • Eclipse IDE: eclipse.ini
  • Jenkins
  • etc.