Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain the location of cacerts of the default java installation?

Tags:

java

security

I am looking on how how to obtain the location of cacerts of the default java installation, when you do not have JAVA_HOME or JRE_HOME defined.

I need a solution that works at least for OS X and Linux.

Yes. java -v is assumed to work :)

like image 604
sorin Avatar asked Aug 13 '12 14:08

sorin


People also ask

How do I get cacerts file?

You can find the cacerts file in the runtime environment installation directory. Contact your system administrator if you do not have permission to edit this file.

How do I find my default Java keystore?

By default, Java has a keystore file located at JAVA_HOME/jre/lib/security/cacerts. We can access this keystore using the default keystore password changeit.

Where are Java certificates stored?

Java certificates are stored in a file called cacerts located at C:\Program Files (x86)\Java\jre1. x. x_xxx\lib\security\ You can open javacpl.exe to get a graphical overview about the content: Step 1.


7 Answers

Under Linux, to find the location of $JAVA_HOME:

readlink -f /usr/bin/java | sed "s:bin/java::"

the cacerts are under lib/security/cacerts:

$(readlink -f /usr/bin/java | sed "s:bin/java::")lib/security/cacerts

Under mac OS X , to find $JAVA_HOME run:

/usr/libexec/java_home

the cacerts are under Home/lib/security/cacerts:

$(/usr/libexec/java_home)/lib/security/cacerts

UPDATE (OS X with JDK)

above code was tested on computer without JDK installed. With JDK installed, as pR0Ps said, it's at

$(/usr/libexec/java_home)/jre/lib/security/cacerts
like image 53
Kuf Avatar answered Oct 04 '22 12:10

Kuf


As of OS X 10.10.1 (Yosemite), the location of the cacerts file has been changed to

$(/usr/libexec/java_home)/jre/lib/security/cacerts
like image 24
pR0Ps Avatar answered Sep 30 '22 12:09

pR0Ps


You can also consult readlink -f "which java". However it might not work for all binary wrappers. It is most likely better to actually start a Java class.

like image 42
eckes Avatar answered Sep 30 '22 12:09

eckes


In MacOS Mojave, the location is:

/Library/Java/JavaVirtualMachines/jdk1.8.0_192.jdk/Contents/Home/jre/lib/security/cacerts 

If using sdkman to manage java versions, the cacerts is in

~/.sdkman/candidates/java/current/jre/lib/security
like image 25
Nish Avatar answered Oct 03 '22 12:10

Nish


For Java 9 onwards, it's in

${JAVA_HOME}/lib/security/cacerts

as opposed to the usual

${JAVA_HOME}/jre/lib/security/cacerts

like image 25
jumping_monkey Avatar answered Oct 04 '22 12:10

jumping_monkey


In High Sierra, the cacerts is located at : /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/security/cacerts

like image 40
arpurush Avatar answered Oct 03 '22 12:10

arpurush


In Ubuntu 20.04.3 LTS, the cacerts is located at: /etc/ssl/certs/java/cacerts

$ java --version
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)
$ ls -lah /usr/lib/jvm/java-11-openjdk-amd64/lib/security/cacerts*
/usr/lib/jvm/java-11-openjdk-amd64/lib/security/cacerts -> /etc/ssl/certs/java/cacerts
like image 32
Felipe Windmoller Avatar answered Sep 30 '22 12:09

Felipe Windmoller