I'd like to find what package is installed on Ubuntu 14.04 (server) that gives access to the javac command. The RHEL line of distros has yum provides for this, but there doesn't seem to be anything similar for the Debian family.
This AskUbuntu question suggests using dpkg -S and apt-file, but neither of these work:
$ sudo dpkg -S `which javac` dpkg-query: no path found matching pattern /usr/bin/javac apt-file search appears to work at first:
$ apt-file search javac javacc: /usr/bin/javacc Except that apt-cache policy shows that this package isn't even installed, so it's obviously not the package that provides javac.
$ apt-cache policy javacc javacc: Installed: (none) Candidate: 5.0-5 How can I find out what package provides the javac command?
2 Answers
In some cases, additional sleuthing is required. In particular,
$ ls -l $(which javac) lrwxrwxrwx 1 root root 23 May 24 2017 /usr/bin/javac -> /etc/alternatives/javac shows that /usr/bin/javac is a symbolic link - so we can either use readlink to drill down:
$ dpkg -S "$(readlink -f $(which javac))" openjdk-8-jdk-headless:amd64: /usr/lib/jvm/java-8-openjdk-amd64/bin/javac or (seeing as it's an update-alternatives link)
$ update-alternatives --query javac Name: javac Link: /usr/bin/javac Slaves: javac.1.gz /usr/share/man/man1/javac.1.gz Status: auto Best: /usr/lib/jvm/java-8-openjdk-amd64/bin/javac Value: /usr/lib/jvm/java-8-openjdk-amd64/bin/javac Alternative: /usr/lib/jvm/java-8-openjdk-amd64/bin/javac Priority: 1081 Slaves: javac.1.gz /usr/lib/jvm/java-8-openjdk-amd64/man/man1/javac.1.gz from which we can pick out the current value:
$ dpkg -S /usr/lib/jvm/java-8-openjdk-amd64/bin/javac openjdk-8-jdk-headless:amd64: /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 2Looks like /usr/bin/javac is a symlink managed by update-alternatives. What do you see if you readlink -f /usr/bin/javac? If it's pointing somewhere else, perhaps check that location with dpkg -S? Or update-alternatives itself can tell you which options you have for a particular link, eg:
$ update-alternatives --config javac There is only one alternative in link group javac (providing /usr/bin/javac): /usr/lib/jvm/java-8-openjdk-amd64/bin/javac Nothing to configure. So then:
$ dpkg -S /usr/lib/jvm/java-8-openjdk-amd64/bin/javac openjdk-8-jdk-headless:amd64: /usr/lib/jvm/java-8-openjdk-amd64/bin/javac