Java Openjdk Installation Issues - bash: javac: command not found

After having installed openjdk

sudo pacman -S jre-openjdk-headless jre-openjdk jdk-openjdk openjdk-doc openjdk-src

but when I want to compile a java program I get this error:

bash: javac: command not found

Any help is appreciated!

It sounds like your PATH doesn’t include the Java bin directory. I don’t know where it goes in Arch, but in CentOS, it’s /usr/lib/jvm... somewhere. I’m not at my desk at the moment to verify.

That binary is provided by java-environment-common which is a dependency of jdk-openjdk, so you should already have it.

What’s the output of:

which javac

and

echo $PATH

It’s /usr/lib/jvm/default/bin.

$ which javac
which: no javac in (/home/kunruh/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin)
$ echo $PATH
/home/mordechai/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin

I tried to add this java directory temporarily to my PATH variable (export PATH=$PATH:/usr/lib/jvm/default/bin) however javac was still not found. Which is coherent because the directory does not contain the javac binary:

$ ls /usr/lib/jvm/default/bin
java  keytool  pack200     rmid         servertool  unpack200
jjs   orbd     policytool  rmiregistry  tnameserv
$ pacman -Si java-environment-common 
Repository      : extra
Name            : java-environment-common
Version         : 3-3
Description     : Common files for Java Development Kits
Architecture    : any
URL             : https://www.archlinux.org/packages/extra/any/java-common/
Licenses        : GPL
Groups          : None
Provides        : None
Depends On      : None
Optional Deps   : None
Conflicts With  : None
Replaces        : None
Download Size   : 2,49 KiB
Installed Size  : 0,00 KiB
Packager        : Felix Yan <felixonmars@archlinux.org>
Build Date      : Sa 16 Mai 2020 11:30:33 CEST
Validated By    : MD5 Sum  SHA-256 Sum  Signature
$ pacman -Si java-environment-common 
Repository      : extra
Name            : java-environment-common
Version         : 3-3
Description     : Common files for Java Development Kits
Architecture    : any
URL             : https://www.archlinux.org/packages/extra/any/java-common/
Licenses        : GPL
Groups          : None
Provides        : None
Depends On      : None
Optional Deps   : None
Conflicts With  : None
Replaces        : None
Download Size   : 2,49 KiB
Installed Size  : 0,00 KiB
Packager        : Felix Yan <felixonmars@archlinux.org>
Build Date      : Sa 16 Mai 2020 11:30:33 CEST
Validated By    : MD5 Sum  SHA-256 Sum  Signature

This symbolic link of java-environment-common is broken beacuse there is no javac in /usr/lib/jvm/default/bin/javac

$ stat /bin/javac
  File: /bin/javac -> /usr/lib/jvm/default/bin/javac
  Size: 30        	Blocks: 0          IO Block: 4096   symbolic link
Device: 10302h/66306d	Inode: 151476      Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2020-11-22 10:11:19.000000000 +0100
Modify: 2020-05-16 11:30:33.000000000 +0200
Change: 2020-11-22 10:11:19.980221770 +0100
 Birth: 2020-11-22 10:11:19.980221770 +0100

EDIT:

/usr/lib/jvm/default/ directory is currently pointing to /usr/lib/jvm/java-8-openjdk in which bin's directory there is no javac binary:

$ ls /usr/lib/jvm/java-8-openjdk/jre/bin
java  keytool  pack200     rmid         servertool  unpack200
jjs   orbd     policytool  rmiregistry  tnameserv

whereas there is a javac binary in

$ ls /usr/lib/jvm/java-14-openjdk/bin
jaotc                jdeps               jrunscript
jaotc.debuginfo      jdeps.debuginfo     jrunscript.debuginfo
jar                  jfr                 jshell
jar.debuginfo        jfr.debuginfo       jshell.debuginfo
jarsigner            jhsdb               jstack
jarsigner.debuginfo  jhsdb.debuginfo     jstack.debuginfo
java                 jimage              jstat
javac                jimage.debuginfo    jstatd
javac.debuginfo      jinfo               jstatd.debuginfo
java.debuginfo       jinfo.debuginfo     jstat.debuginfo
javadoc              jjs                 keytool
javadoc.debuginfo    jjs.debuginfo       keytool.debuginfo
javap                jlink               rmic
javap.debuginfo      jlink.debuginfo     rmic.debuginfo
jcmd                 jmap                rmid
jcmd.debuginfo       jmap.debuginfo      rmid.debuginfo
jconsole             jmod                rmiregistry
jconsole.debuginfo   jmod.debuginfo      rmiregistry.debuginfo
jdb                  jpackage            serialver
jdb.debuginfo        jpackage.debuginfo  serialver.debuginfo
jdeprscan            jps
jdeprscan.debuginfo  jps.debuginfo

So I probably just have to change this link directory but I think there is an arch tool for this. Would it have worked when I simply additionally installed the java 8 openjdk package for development?

Its archlinux-java from extra/java-runtime-common.

Which version of Java are you trying to use? Sounds like Java 8 is your default right now as you’ll see by running:

archlinux-java status

See Java - ArchWiki

Thanks for your help!

$ archlinux-java status
Available Java environments:
  java-14-openjdk
  java-8-openjdk/jre (default)

I had to set the default java version with this:

sudo archlinux-java set java-14-openjdk

And now I am able to compile some java classes :+1:

1 Like