Well,I was trying to install forge on my linux machine(Kali-Linux).While on the was I was and still am unable to access the forge file(.jar).Due to an issue in which there is a lack of a command called “java”.
The current problem I am having is sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-16.0.1/bin/java 1
while using this command I get a response as update-alternatives: error: cannot stat file '/bin/java': Too many levels of symbolic links.
When I try to ls in the /bin.The java symbolic link has a weird symbol(Just wanted to mention it cause it looked weird)
Is there anyway to fix this problem?
Advertisement
Answer
The “too many levels of symbolic links” message means that 40 symlinks have been traversed in attempting to resolve a path to an object.
It nearly always happens because you have a symlink that directly or indirectly points to itself. And the purpose of the limit (and the check) is to prevent the kernel going into an infinite loop.
So, why it is it happening here? Well, it is not entirely clear. But it seems like an earlier update-alternatives
run has left some “wreckage” in the form of bad symlinks. If “/bin/java” already points to “/etc/alternatives/java”, then “/etc/alternatives/java” should be a symlink to … somewhere else.
Try the following:
Use
update-alternatives --remove-all java
to clear out any alternatives for thejava
command. (If this fails with the same problem, try step 2 first, then retry this step. Adding--force
might help too.)Remove the “/bin/java” and “/usr/bin/java” symlinks if they still exist.
Make sure that you have actually installed Java (already!), and “/usr/lib/jvm/jdk-16.0.1/bin/java” is the correct path for the executable. Run
/usr/lib/jvm/jdk-16.0.1/bin/java -version
to check.Run
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-16.0.1/bin/java 1
.
Note that update-alternatives
does not actually install anything. For the command to work properly, you need to have installed (in this case) a Java JRE or JDK or a Kali Java package already.
Note that it cannot do any real harm to remove “alternatives” symlink chains that are broken. You can always clean them out and rebuild them. (By hand, if necessary.) The alternatives mechanism is just a fancy way of managing symlinks.