To fix it simply run the following commands

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.1/bin/java 3
sudo update-alternatives --config java

The first correct the errors you made where you had /usr/lib/jvm it should have been /usr/bin/java. The second command gives you the opportunity to pick the default version you want.

Answer from George Udosen on askubuntu.com
🌐
Arch Linux Forums
bbs.archlinux.org › viewtopic.php
[Solved] Javac not found - JDK and JRE both installed / Newbie Corner / Arch Linux Forums
September 25, 2017 - ewaller@turing ~ 1005 %pacman -Qo /usr/lib/jvm/default/bin/javac /usr/lib/jvm/java-7-openjdk/bin/javac is owned by jdk7-openjdk 7.u151_2.6.11-1 ewaller@turing ~ 1006 %
Discussions

Debian 8 -bash: /usr/bin/java: No such file or directory - Unix & Linux Stack Exchange
On a new Debian system I installed JRE using sudo apt-get install default-jre Then I downloaded a jar-file and tried running it: java -jar server.jar The file threw an exception: java.lang. More on unix.stackexchange.com
🌐 unix.stackexchange.com
May 16, 2019
Alternative for java-home not installed: failed to read link /usr/java/default: No such file or directory
I am trying to run this formula on a fresh CentOS 7.3 Minimal. I am kind of confused about /usr/java/default. The problem is that my pillar file is identical to pillar file in this formula. Pillar ... More on github.com
🌐 github.com
5
October 11, 2017
java - unable to run javac on Ubuntu - Stack Overflow
I'm trying to run javac on a Ubuntu terminal. But I get the following: $ javac The program 'javac' can be found in the following packages: * openjdk-6-jdk * ecj * gcj-4.4-jdk * gcj-4.6-jdk ... More on stackoverflow.com
🌐 stackoverflow.com
linux - Java -version giving me a "no such file or directory" - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › saltstack-formulas › sun-java-formula › issues › 49
Alternative for java-home not installed: failed to read link /usr/java/default: No such file or directory · Issue #49 · saltstack-formulas/sun-java-formula
October 11, 2017 - 192.168.0.106: ---------- ID: java-install-dir Function: file.directory Name: /usr/share/java Result: True Comment: Directory /usr/share/java is in the correct state Directory /usr/share/java updated Started: 01:34:39.409504 Duration: 0.679 ms Changes: ---------- ID: sun-java-remove-prev-archive Function: file.absent Name: /usr/share/java/jdk-8u144-linux-x64.tar.gz Result: True Comment: File /usr/share/java/jdk-8u144-linux-x64.tar.gz is not present Started: 01:34:39.410503 Duration: 0.285 ms Changes: ---------- ID: download-jdk-archive Function: cmd.run Name: curl -b oraclelicense=accept-secur
Author   saltstack-formulas
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-8211012
postun(jdk-11-2000:11-ga.x86_64) scriptlet failed, exit ...
1:jdk-11-2000:11-ga ################################# [100%] [testuser@emb-jh-01 staged]$ cd /usr/java [testuser@emb-jh-01 java]$ ls default jdk-11 latest [testuser@emb-jh-01 java]$ sudo rpm -e jdk-11 failed to read link /usr/bin/javac: No such file or directory warning: %postun(jdk-11-2000:11-ga.x86_64) scriptlet failed, exit status 2 [testuser@emb-jh-01 java]$
Find elsewhere
🌐
Ask Ubuntu
askubuntu.com › questions › 1321393 › line-56-bin-java-no-such-file-or-directory
16.04 - line 56: /bin /java: no such file or directory - Ask Ubuntu
March 5, 2021 - sudo update-alternatives --config java There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java Nothing to configure. sudo update-alternatives --config javac There are 2 choices for the alternative javac (providing /usr/bin/javac) Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-8-oracle/bin/javac 1081 auto mode 1 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode * 2 /usr/lib/jvm/java-8-oracle/bin/javac 1081 manual mode Press <enter> to keep the current ch
🌐
Zimbra
forums.zimbra.org › home › board index › zimbra collaboration server › installation and upgrade
line 56: /bin /java: no such file or directory - Zimbra Forums
I run this: sudo update-alternatives --config java There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java Nothing to configure. sudo update-alternatives --config javac There are 2 choices for the alternative javac (providing /usr/bin/javac) Selection Path Priority Status ------------------------------------------------------------ 0 /usr/lib/jvm/java-8-oracle/bin/javac 1081 auto mode 1 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode * 2 /usr/lib/jvm/java-8-oracle/bin/javac 1081 manual mode Press <enter> to keep th
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
Can't install java 8 - bash: /usr/bin/java: No such file or directory - Linux Mint Forums
May 2, 2020 - export PATH=$PATH:$JAVA_HOME/bin Save and close the file. Once again you need to type the following command to activate the path settings immediately: source /etc/profile and after that I success run ... java -version from any folder Also this help. How add JAVA_HOME for all users? Help: https://stackoverflow.com/questions/246 ... -all-users 1. Set JAVA_HOME Open in sudo mode the file ... JAVA_HOME=path_to_jdk E.g. ... PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" JAVA_HOME=/usr/java/jdk1.8.0_251
🌐
Red Hat
bugzilla.redhat.com › show_bug.cgi
1324714 – Run alternatives --config java breaks symlink to javaws
August 8, 2017 - Red Hat Bugzilla – Bug 1324714 · This site requires JavaScript to be enabled to function correctly, please enable it · Privacy Contact FAQ Legal
🌐
Apache
lists.apache.org › thread › rgg5jbdr1w9yy90t5jkkjl4046v45kry
Installation error - No such file or directory: 'javac'
Email display mode: · Modern rendering · Legacy rendering · This site requires JavaScript enabled. Please enable it
🌐
Stack Exchange
unix.stackexchange.com › questions › 603386 › unable-to-build-using-java-openjdk-14-bin-sh-javac-command-not-found
bash - Unable to build using Java OpenJDK 14. /bin/sh: javac: command not found - Unix & Linux Stack Exchange
Just make sure the second one that includes that path is after the first one. As for the find I was only checking in bin directories, adjust the find command to have /usr/lib/ and it would return the path to javac but it looks like you're getting ...
Top answer
1 of 4
4

This is a $PATH issue. $PATH is an environment variable that contains a list of directories to search when looking for an executable. You can see your current $PATH via echo $PATH.

javac: command not found indicates javac is not in any of the directories in your $PATH. You need to add the directory with javac in it into your $PATH, or add javac to one of the directories in your $PATH -- but the former is much preferable.

To temporarily add a directory for your current shell:

export PATH=/some/directory:$PATH

If you want to use that permanently, add the same line to ~/.bashrc. For example, I use JDK 8 on the pi that I have installed to /usr/local, so I have a line:

export PATH=/usr/local/jdk1.8.0/bin:$PATH

That directory contains java, javac, jar, etc.

You mentioned that java appears in be in your path since "java -version comes up with the java number and package so java is definitely installed" although you do not actually say what that number and package are. I suspect you have multiple versions installed, one of which is just a jre and thus does not include javac.

2 of 4
3

It's likely you just installed the JRE and not the full JDK. If you're running Raspbian Wheezy, you can use

apt-get install openjdk-7-jdk

to install javac. (If you're using the older Debian Wheezy OS, it works with the Sun JVM, so you can install that with the instructions here: http://www.savagehomeautomation.com/pi-jdk . The standard Raspbian OS isn't supported by Sun yet, so you have to use Openjdk with it.)

🌐
Red Hat
bugzilla.redhat.com › show_bug.cgi
1659646 – Installing OpenJDK 11 breaks alternatives javac
December 17, 2018 - Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla · RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue ...