Fix: Unable to lock the administration directory

Newcomers to GNU/Linux often run into some trouble when a command needs to be executed with root superuser privileges. Sometimes these commands will throw out “unable to lock the administration directory” error messages, especially when attempting to install updates or new applications from the command line. This error message is often accompanied by a rather frustrating question: “are you root?”

Getting root privileges is like using an elevated command prompt in Microsoft Windows, only it can actually be much easier since a simple command will give you the authority you need without so much as opening another window. In most cases, you can fix this error right now with just a few keystrokes.

Method 1: Using sudo in Front of Commands on Linux

If you’re getting the error message when you’re doing something administrative like installing a new package, then no matter how many times you run commands to do it and no matter what package name you use you’ll still get this message.

Try typing sudo in front of the command you’re running instead. For instance, if you were trying to install a package on a Linux distro that uses the apt-get package manager, then you can type sudo apt-get install pgkName, having replaced pgkName with the name of the software that you were trying to install.

Notice that you’re now being asked for your password. Once you enter it, things will work as normal. You won’t have to open another window to get to an elevated command prompt like you do in Windows to get full powers to do things. The next command you type, though, will be run at your regular user level again. If you want to run another command with superuser powers like if you were trying to install another package, then type sudo in front of it again.

Should this have fixed your problem, then you don’t need to do any further playing around. This isn’t a problem per say, it’s a fact of life for seasoned GNU/Linux users since it protects your computer from unauthorized access.

Method 2: Run sudo Graphically

While this works for command line programs just fine, you might want to sometimes run a graphical program as the superuser. Since the root user can do anything to the system they’d like, you want to be careful when using sudo. However, you’ll sometimes need this privilege to work with system cleaning software like BleachBit.

Instead of prefacing the command with sudo in this case, type gksu in front of it. You’ll get a little box asking for your password, and once you’ve entered it the program will run like normal. Don’t be alarmed if the window of the spawned application doesn’t match your other windows – the root account probably doesn’t have a nice color scheme set.

You might also want to try kdesu if you’re on a system using the K Desktop Environment.Try placing kdesu in front of any GUI command you’re required to run as root if you get an error message about gksu or if you know you’re running the Plasma desktop.

Notice that you do receive a warning message about how the root user can cause damage to your system when running these commands, which is another reminder about how you should be cautious when doing so to avoid harming your Linux installation.

Method 3: Becoming the root User

On some distributions you can run su – to become the root user after typing a password. This should work on distributions like Fedora and CentOS that don’t hash out the root account. Notice that your prompt changes from a $ symbol to a # symbol when you do this. This is to show that you now have superuser root access.

Some distributions like Ubuntu and the various ones based on it don’t support this. Use sudo -i on these systems to receive a root login shell. Either way, you won’t have to preface administrative commands with sudo when you’re logged in this way, but please keep in mind that with great power comes great responsibility. If you’re on a server or something of that nature, then your system administrator might even have certain rules to follow about what you can and can’t do with the root account.

Users who are on their own machines are simply advised not to delete anything they didn’t create themselves.

ABOUT THE AUTHOR

John Rendace


John is a GNU/Linux expert with a hobbyist's background in C/C++, Web development, storage and file system technologies. In his free time, he maintains custom and vintage PC hardware. He's been compiling his own software from source since the DOS days and still prefers using the command line all these years later.
Back to top button