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.
Debian 8 -bash: /usr/bin/java: No such file or directory - Unix & Linux Stack Exchange
Alternative for java-home not installed: failed to read link /usr/java/default: No such file or directory
java - unable to run javac on Ubuntu - Stack Overflow
linux - Java -version giving me a "no such file or directory" - Stack Overflow
Videos
To restore your /usr/bin/java link, you should run
sudo update-java-alternatives -a
If you were using Debian 9 (as mentioned initially), you shouldn’t have run into these issues, since OpenJDK 8 is the default there and OpenJDK 7 isn’t even available. To fix things so that you can run version 52 classes (i.e. Java 8 classes), install OpenJDK 8:
sudo apt install openjdk-8-jre
On Debian 8 you can install OpenJDK 8 from backports:
echo deb http://archive.debian.org/debian jessie-backports main | sudo tee /etc/apt/sources.list.d/jessie-backports.list
echo 'Acquire::Check-Valid-Until "false";' | sudo tee -a /etc/apt/apt.conf
sudo apt update
sudo apt -t jessie-backports install openjdk-8-jre
(See Failed to fetch jessie backports repository for details.)
You’ll then need to specifically choose OpenJDK 8 as the default:
sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
(To see the possible values, run /usr/sbin/update-java-alternatives -l.)
If you get error as below:
bash: /usr/bin/java: No such file or directory
Run:
apt-get install libc6-i386
Some 32bit libs are missing
This is because there are some 32-bit libraries missing in your Ubuntu 64-bit. Run:
apt-get install libc6-i386
you can refer to this Stack Overflow post for more information
I ran into a similar issue and got it solved by
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6-i386
If apt-get was not able to locate the libc-i386 package you may need to --add-architecture and run apt-get update.
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.
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.)