Ubuntu – Adding apt-get to sudoers file

aptsudo

I've grown tired of always invoking apt-get update and apt-get upgrade under sudo and typing my password, so I have added the following line to my /etc/sudoers file using visudo:

<myusername> ALL=NOPASSWD: /usr/bin/apt-get

Unfortunately when I invoke apt-get I am met with the following error:

<myusername>@sputnik:~$ apt-get update
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
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?

I have tried to add the following (fairly obvious) line to /etc/sudoers too but to no effect

<myusername> ALL=NOPASSWD: /usr/bin/dpkg

What must I do?

Best Answer

Even with that configuration in /etc/sudoers, you will still need to use sudo to run apt-get as root. The difference is that with proper configuration you will no longer need to type in your password.

Related Question