Before writing the original issue I am facing, I think it'd be best to provide some background.

Background I was trying to register a new source to get packages when running apt-get to finally install azure-iot-sdk-c-dev to use the code to communicate to IoT Hub.

I ran in to issue when tried running the following command.

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys xxxxxxxxxxxxxx

From the error it seemed that my PI doesn't have dirmngr directory. So I started looking for solutions. One of the solution was to use the following commands

sudo apt remove gnupg

sudo apt install --reinstall gnupg2

sudo apt install dirmngr

Even though I was informed about the potential damage of the first command I assumed performing the second command would fix things up, but the second command is not running.

Issue It is giving me errors like sudo: apt: command not found to fix that I tried the following

sudo apt-get install --reinstall gnupg2

apt-get update && apt-get upgrade

But both errors out stating -bash: apt-get: command not found

EDIT 1 After trying sudo aptitude install apt, I get the following, enter image description here I tried the following afterward enter image description here

Then manually created preferences enter image description here

now stuck at update enter image description here

  • What does find / -name apt-get shows ? Does it lists /usr/bin/apt-get. If yes, then try using sudo /usr/bin/apt-get with install , update or upgrade. Aug 24, 2018 at 13:48
  • Ok will try once I reach home Aug 24, 2018 at 15:24
  • Hi, I didn't find /usr/bin/apt-get listed, what next try seeing whether I have gdebi or one of the programs mentioned by @AFH. Aug 27, 2018 at 0:29
  • Not sure what exactly is going on in your system. You should try suggestions by @AFH depending on what you have installed. Best of Luck :) Aug 27, 2018 at 2:07

1 Answer 1


Removing gnupg should not have affected whether apt and apt-get are installed, though removing some libraries may stop them working correctly.

Possible solutions depend on what you have installed:-

  • if you have gdebi, then you can install apt* from the .deb files down-loaded from LaunchPad;
  • if you have aptitude or synaptic, you can use one of these to restore apt*;
  • otherwise, mount the install disc for the system, then modify PATH to reference the utilities on the install disc;
  • if all else fails, boot the install disc and reinstall the OS over the top.

If you use an install disc, make sure you down-load the latest for the release you are running.

There may be other solutions (such as using chroot to address your installed system from a booted install disc), but without understanding how apt* were lost, I am reluctant to suggest more.

  • Thanks for the response, so something did get deleted? and My options are to repair or reinstall? Aug 24, 2018 at 15:42
  • 1
    Did you follow @C0deDaedalus' suggestion (you will find locate a lot faster than find)? With what result? Obviously some sort of repair is needed: you will need to find which method involves the least work. Since I don't know what has gone wrong with your system, I don't know how much work each of my options will entail, though I expect the last will not be the easiest.
    – AFH
    Aug 24, 2018 at 16:03
  • I will follow his suggestion once I reach back home in evening, then will post my updates. Thanks for the help though. Aug 24, 2018 at 16:26
  • When I run the command as suggested by @C0deDaedalus, I see a lot of find commands with permission denied message and I do not see /usr/bin/apt-get either. I do not know whether I have gdebi, synaptic or aptitude but I will make sure to learn to find to see whether these programs are installed or not. In case I do not find the programs installed can I from the internet try installing those first? Please pardon me if I've missed something obvious, I'm completely new to this and Linux. Aug 27, 2018 at 0:41
  • I seem to have aptitude, I used dpkg -l | grep -E '^ii' | grep aptitude. Now I need to learn to use aptitude to restore apt*. Will keep you posted sir. Aug 27, 2018 at 1:04

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.