I'd like to upgrade java from 8 to 11 as recommended for Jenkins 2.303.1, I'm reading the guide in https://www.jenkins.io/doc/administration/requirements/upgrade-java-guidelines/, but I don't know what to do in step:
Use a package manager to install the new JVM. Make sure the default
JVM is the newly installed version. If it is not, use the correct java
command in the Jenkins startup scripts (/etc/default/jenkins or
/etc/init.d/jenkins).
does it mean install Java 11 and set java 11 is default one?
Note: since June 2022, you do not have a choice anymore.
JDK 11 will need to be the one running Jenkins.
It does not have to be the "default" on your system. Only the one selected in the command use to run Jenkins.
Jenkins requires Java 11 (Basil Crow)
Beginning with Jenkins 2.357 (released on June 28, 2022) and the forthcoming September LTS release, Jenkins requires Java 11.
Additionally, beginning with Jenkins 2.355 (released on June 14, 2022) and Jenkins 2.346.1 LTS (released on June 22, 2022), Jenkins supports Java 17.
Plugins have already been prepared in JENKINS-68446.
Use the Plugin Manager to upgrade all plugins before and after upgrading to Jenkins 2.357.
Warning regarding JAXB
Prior to Java 11, Java Architecture for XML Binding (JAXB) was part of the Java Platform, and one could use it without adding a third-party dependency.
Beginning with Java 11, JAXB is no longer a part of the Java Platform and requires adding a third-party dependency.
Thanks to work done several years ago by Baptiste Mathus and others, a JAXB Jenkins plugin is available, which provides the JAXB library to Jenkins plugins in the form of a plugin-to-plugin dependency.
The vast majority of plugins have already been prepared to support Java 11 via the JAXB plugin in JENKINS-68446.
Jenkins users need only upgrade plugins to compatible versions as documented in the Released As field in Jira.
It is critical to use the Plugin Manager to upgrade all plugins before and after upgrading to Jenkins 2.357.
Failure to upgrade plugins to compatible versions may result in ClassNotFoundException, NoClassDefFoundError, or other low-level Java errors.
Upgrade
Docker
The official Jenkins Docker images have been based on Java 11 for many months, with Java 8 available as a fallback and Java 17 available in preview mode.
Beginning with Jenkins 2.357, the Java 8 images will be retired and the Java 17 images will transition from preview to general availability (GA). Users of the official Jenkins Docker images need not install or configure Java on their own, as it comes preinstalled in the image.
OS packages
Users of the official Jenkins OS packages for Debian, Red Hat, and SUSE Linux distributions should note that these packages are agnostic to the Java vendor. >
In other words, you must bring your own Java package. One straightforward way to do this is to install Java 11 from your Linux distribution, as described on the package download site
Recommenced Garbage collection options
-XX:+AlwaysPreTouch
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=${PATH}
-XX:+UseG1GC
-XX:+UseStringDeduplication
-XX:+ParallelRefProcEnabled
-XX:+DisableExplicitGC
-XX:+UnlockDiagnosticVMOptions
-XX:+UnlockExperimentalVMOptions
-Xlog:gc*=info,gc+heap=debug,gc+ref*=debug,gc+ergo*=trace,gc+age*=trace:file=${PATH}/gc.log:utctime,pid,level,tags:filecount=2,filesize=100M
-XX:ErrorFile=${PATH}/hs_err_%p.log
-XX:+LogVMOutput
-XX:LogFile=${PATH}/jvm.log
Agents
For best results, it is recommended to run agents with the same version of Java as the version used on the controller.
Use the Versions Node Monitors plugin to verify that agents are running a compatible version of Java.
Running the Jenkins remoting process on an agent with Java 11 or 17 does not imply that you need to run your builds with the same version of Java.
You can continue to use any desired version of Java for individual builds.
I opted to not install Java on the system, and followed the below approach:
Go to Java 11 Downloads (registration on oracle.com required)
Download the latest Java 11 Compressed Archive (zip) file. At the time of writing: jdk-11.0.15_windows-x64_bin.zip
Unzip this on your build server, keep the path where you extracted to for step 5
Backup Jenkins Home, especially your jenkins.xml file (same folder as jenkins.war).
In Jenkins.xml, update Executable to extracted path, e.g. C:\Java\jdk-11.0.11\bin\java.exe
Restart Jenkins Service
However you have (OpenJDK) 11 installed, as long as you have either JAVA_HOME=/path/to/jdk11 and PATH=$JAVA_HOME/bin:$PATH or explicitly run /path/to/jdk11/bin/java -jar jenkins.war or if you type java -version and it returns "11", you are fine.
Note: that is to launch jenkins. You can set the JDK available to your jenkins jobs from within Manage | Global Tools Configurationtion.
2nd Note (updated): the documentation has been updated (2021-09-16) ... The default Docker image jdk as of 2.303.1 is now 11, so you don't need to append ”-jdk11", rather users must append "-jdk8" if users want to stick to 8.
if you have Centos you can do the following(i have done this for Centos7 and Jenkins 2.367)
sudo yum install java-11-openjdk
yum install output
if have issues with repos and you want do this manually
you get the rpm's that you want and then :
first update the dependency .
sudo rpm -Uvh tzdata-java-2020a-1.el7.noarch.rpm
and then
sudo rpm -Uvh java-11-openjdk-headless-11.0.8.10-1.el7.x86_64.rpm
sudo rpm -Uvh java-11-openjdk-11.0.8.10-1.el7.x86_64.rpm
then you can give
sudo update-alternatives --config java
to find the java path of java 11 --> /usr/lib/jvm/java-11-openjdk-11.0.8.10-1.el7.x86_64/bin/java
it should not be the default, if you don't want to ,you can just copy it
and use it to jenkins nodes Java path at configure nodes
jenkins JavaPath
You have two options: You can globally install Java 11 on your system, for example using a package manager like apt. You would then make Java 11 your default Java.
The other option is to manually install Java, for example OpenJDK, and extract it to, for example, /opt/java and adjust the Jenkins startup script to use that specific Java installation.
I just upgraded a Jenkins installed from apt packages (from: http://pkg.jenkins-ci.org/debian/) with the following steps (inspired by: https://www.jenkins.io/doc/book/installing/linux/)
First, install java 11:
sudo apt install openjdk-11-jre
Then check java -version
which may still show openjdk version "1.8.[x]"
If so, do choose a java-11 alternative with:
update-alternatives --config java
Then java -version should show openjdk version "11.0.[x]"
Then you can do:
systemctl restart jenkins
docker exec -it <container_id> /bin/bash
If permission denied error, then,
docker exec -u 0 -it <container_id> /bin/bash
sudo apt-get update
sudo apt-get install openjdk-11-jdk
export PATH=$JAVA_HOME/bin:$PATH
java -version
I am having trouble running Aptana Studio 3 on a Mac where multiple versions of JDK are installed (i.e., jdk1.8.0_271.jdk and jdk-11.0.2.jdk). Aptana requires JDK 8, and when only it is in the Library/Java/JavaVirtualMachines will Aptana run, otherwise, I get startup fatal errors. I need Open JDK 11 for another application and it runs with both JDKs installed. I tried to set JDK 8 as the default in a .bash_profile using the following, but for some reason (probably an obvious one that answers this question) Aptana doesn't recognize the default setting and only runs when I remove the jdk-11.0.2.jdk from JavaVirtualMachines. I know there is a version control package jenv, but I don't have it installed, and not sure it would fix the problem anyway. Appreciate any pointers on how to resolve this, if I can/should add a shell to the package contents of Aptana, proper mods on the commands below, etc. Running Mac Mojave 10.14.6. Thanks.
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8*)
export JAVA_11_HOME=$(/usr/libexec/java_home -v11.*)
alias java8='export JAVA_HOME=$JAVA_8_HOME'
alias java11='export JAVA_HOME=$JAVA_11_HOME'
#default java8
export JAVA_HOME=$JAVA_8_HOME
macOS picks the most recent version of JDK. You have few options here:
remove files (backup) of JDKs that you don't want to use
/Library/Java/JavaVirtualMachines/${JDK_VERSION}/Contents/Info.plist
make sure to setup Terminal session for using give version
# inside ~/.zshrc put
export JAVA_HOME=$(/usr/libexec/java_home -v ${VERSION_OF_YOUR_CHOICE})
export PATH=${JAVA_HOME}/bin:${PATH}
use some tool to maintain JDK versions
As you already mentioned, you can use some existing tool (e.g. jenv)
I need to update Java version
java version "1.4.2"
I don't want change version of my jdk, so if I update java, will JDK update too?
EDIT
#UnholySheep
You mean you want to update the JRE (runtime environment)? That is
indeed separate from the JDK
java -version will update only if you point the java environment variable to the new JDK/JRE installation.
You can have multiple JDK installations and switch between them whenever you like. For the current JDK in use you just have to set (On Windows) the JAVA_HOME environment variable to point to the correct JDK folder you intend to use at the moment.
Of course, this is only helpful for use in the command line. If you are using an IDE it's even simpler, you can choose/switch the JDK you want to use on every Java Project from the Project Settings.
For Linux, you can change the current JDK in use like this:
export $JAVA_HOME=/urs/lib/jvm/jdk1.8.0_144/jre
export PATH=$JAVA_HOME/bin:$PATH
sudo update-alternatives --config java
if you want to upgrade your Java version in your Linux system
then you can go with
sudo upgrade java
I have a linux box (Ubuntu server 14.04). I installed jdk7 via apt-get and Oracles Java 8 manually by extracting the tarball.
How can I switch between the Java versions from a bash session?
I suppose it should be done via "alternatives", but the details are not clear to me.
Switching java is more than calling one of the two java executables. There are other binaries (e.g. javac) and some tools refer to different files within the java installation directories (think of cacerts for example).
An optimal solution would simulate the effects of having only one of the two versions installed at any time.
Example: Using maven it is possible to set JAVA_HOME, but if some process started by maven calls java, JAVA_HOME is ignored.
I think Debian has Java 8 meanwhile. Does anybody know how they deal with this issue?
Is the alternatives mechanism only usable for individual binaries or can it be used for a complete "suite", too?
You can use this command to get a list of installed jdk's and easily choose one you would like to use:
sudo update-alternatives --config javac
I'm not sure that I fully understand the question, but you could either use an environment variable in your bash session that holds the path to your java executable or you could put a symbolic link somewhere for the same purpose.
For example
export JAVA_EXEC=/usr/lib/jvm/java-8-oracle/jre/bin/java
$JAVA_EXEC -version
$JAVA_EXEC -jar cooljar.jar
Or with symlink, like the "alternatives" you mentioned
ln -s /usr/lib/jvm/java-8-oracle/jre/bin/java /usr/local/bin/java
/usr/local/bin/java -version
ln -s "${SOME_JAVA_PATH}" /usr/local/bin/java
/usr/local/bin/java -version
How to upgrade the java version from 1.4 to next version in linux ?
When i give a command java -version , getting output having java 1.4 version.
I want to upgrade from java 1.4 to java 1.6 version. How to achieve this ?
While you could download Java off the net, extract it and install it, you should stick to using your distribution's package manager in order to ensure proper version management and maintainability of your OS. Each Linux distribution has its own package manager (Debian uses apt/dpkg, Red Hat uses yum and so forth), so you should familiarize yourself with the relevant package manager and take it from there.
(Also, positively consider #Thilo's advice about skipping 1.6.)
Using which java should be able to tell you where java is installed on your local Linux server. It is likely to be a symbolic link to /usr/bin/java (I say usually because on AIX it is different).
Now, assuming you have a new version of JAVA installed in /usr/local/java_xxxx (you decide which one you want), simply update your symbolic link to java and javac.
ln -s -v /usr/local/java_xxxx/java /usr/bin/java
ln -s -v /usr/local/java_xxxx/javac /usr/bin/javac
And now java -version should give you the latest installed copy. For other 'detailed' instructions look here