How can I install the
$ apt-get install sudo E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
If you've actually deleted the
sudo command, you can reinstall the package that provides it by running:
pkexec apt-get update pkexec apt-get --reinstall install sudo
You must be logged in as an administrator to do this, of course. If you're using an account who was allowed to use
sudo (back when
sudo existed on the system), that should work fine.
On a minimal system or Ubuntu server system, Polkit may be unavailable, and with some configurations you will not be able to run the
pkexec command over an SSH session.
You have indicated that
pkexec, while not deleted like
sudo, is also broken. Specifically, on your system it has the wrong ownership or permissions. It is supposed to be setuid root, but it is not, and therefore it cannot be used.
It would be useful to know how
/usr/bin/sudo was deleted, and how
/usr/bin/pkexec's permissions (or ownership) got changed. These are two, seemingly separate breaking changes to your system. If a recursive (
chmod has been performed on
/usr/bin, that would explain how
pkexec's permissions were changed, and an appropriate fix would do more than just changing them back for that one executable.
With that said, if the only two things wrong with your system are that
sudo is missing and
pkexec has wrong permissions or ownership, this is still easily fixed, though you will have to reboot into recovery mode or chroot in from a live environment. I suggest recovery mode.
/readwrite by running:
mount -o remount,rw /
pkexechas correct ownership:
chown root:root /usr/bin/pkexec
chmod 4755 /usr/bin/pkexec
exitand follow the prompts), or reboot with
sudopackage by running
This has the advantage of working whether or not any Internet connection is available in recovery mode, without involving downloading
.deb files and manually installing them. With
apt-get will replace all the package files for
sudo, which can fix additional problems. Plus, this also fixes your broken
However, this is not the only approach. In particular, the method given in San Lin Naing's answer should work, too. The main difference is that, in the method given here, no package management operations are carried out in the chroot, which is only used to repair
pkexec so it can then be used to manage packages when booted normally.
root permission to install any software. But, you had deleted the
If you have access as a
root, you may be able to install
Reference to this answer.
Try to start with
bash mode with
Advanced options for Ubuntu.
Ubuntu, with Linux x.x.x-xx-generic (recovery mode).
root Drop to root shell prompt
mount -o rw,remount /command to gain read write access.
apt install sudo. Follow on screen instructions.
If installation finished, It is done!
If not, this may need network connection.
Lets reboot your system to normal boot and download required files.
Ctrl + D will go menu page again and choose
resume. This will go to normal boot.
You may need to install sudo offline. This may be another research. Here you can find
.deb package. You can download with your OS version. Download your file that is
sudo_1.8.19-3_xxxx.deb. And then remember your download
Reboot your system in
bash mode (recovery mode) again and follow 1-6 steps.
dpkg -i *file_path/sudo_1.8.19-3_xxxx.deb. This will install
Ctrl + D and choose
resume to normal boot.
yes i acidentlly deleted the sudo file. the output of ls -l /usr/bin/sudo is cannot access '/usr/bin/sudo': No such file or directory
Just a thought:
You still have the media (DVD / USB stick) from which you installed Ubuntu to your system?
/usr/bin/sudofrom the live system to the mounted partition.
Maybe you could boot your system to recovery mode via grub. From there you could try to check the system integration via dpkg, which maybe lets you solve your problem. Or, after that, since your partition has been mounted with read/write permissions, you could install sudo without using the sudo command by using the root menu entry. You should update via apt-get and maybe try the use of
apt-get install -f and
dpkg --configure -a first.
You can build
sudo from source
mkdir sudo-src cd sudo-src apt-get source sudo cd sudo-x.y.z ./configure --prefix=$HOME make make install