I have done a terrible deed while linking javac to /usr/bin

I accidentally pasted wrong command line and now I cannot use sudo anymore and thus, I can't access any file or folder which needs permission.

It says

bash: /usr/bin/sudo: Too many levels of symbolic links

The command line which I wrongly paseted is

sudo ln -f -s sudo ln -f -s /opt/jdk1.8.0_151/bin/javac /usr/bin

But it should be

sudo ln -f -s /opt/jdk1.8.0_151/bin/javac /usr/bin

But I already messed up. So, please, if anyone have any idea of how I can fix that, I'll be very thankful.

  • Updated my answer to try to su to root and see if that works. – Terrance Jan 5 '18 at 3:42
  • Do you get a grub menu at boot time? You can start a root shell from there (recovery mode → root shell). The filesystems will be read-only at first but you can remount them read-write (mount -o rw,remount /) and then fix your broken sudo. – PerlDuck Jan 7 '18 at 13:44

Run the following to fix the error.

/usr/bin/sudo rm /usr/bin/javac

If the above line doesn't work, see if you can change to the root user then try again:

su root
rm /usr/bin/javac

Then rerun the correct line.

Hope this helps!

| improve this answer | |
  • When I run your command line, terminal gives me this error :- ~$ /usr/bin/sudo rm /usr/bin/javac bash: /usr/bin/sudo: Too many levels of symbolic links – Battle Hawk Jan 5 '18 at 1:43
  • @BattleHawk That is interesting. I ran your first command in a VM to test it out and that is what it took to fix it. Turns out that sudo links to javac in the /usr/bin folder. I would recommend then booting to a LiveCD and removing the javac link from the /usr/bin folder. – Terrance Jan 5 '18 at 1:54
  • @BattleHawk Maybe follow some of the advice I gave in this answer to get the host booted to a LiveCD to fix it: askubuntu.com/a/634013/231142 – Terrance Jan 5 '18 at 1:56
  • su root gives me this ~$ su root Password: su: Authentication failure – Battle Hawk Jan 6 '18 at 4:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.