3

I accidentally deleted all the files in the folder /etc/apt which contains sources.list.

Now I am not able to install any software via terminal; I get this error every time:

Package has no installation candidate

How can I fix this? Thank you in advance :-)

Zanna
  • 69,223
  • 56
  • 216
  • 327
shiv
  • 41
  • 1
  • 1
  • 6
  • This is the seed of an answer that, if I am on the right track, I hope someone will test and expand in the answer section: see [How can I restore configuration files](https://askubuntu.com/questions/66533/how-can-i-restore-configuration-files). Since you can't use APT, you'll have to download the packages listed by `dpkg -S /etc/apt` and install them using `dpkg -i`. You may need some help from [How can I restore the default repositories](https://askubuntu.com/questions/124017/how-do-i-restore-the-default-repositories) and I'm not sure this will work. – Zanna Jun 28 '18 at 20:28

1 Answers1

2

You can create sources.list in /etc/apt directory.

sudo touch /etc/apt/sources.list

Open file with nano.

sudo nano /etc/apt/sources.list

Copy following content in file.

#------------------------------------------------------------------------------#
#                            OFFICIAL UBUNTU REPOS                             #
#------------------------------------------------------------------------------#


###### Ubuntu Main Repos
deb http://in.archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse 

###### Ubuntu Update Repos
deb http://in.archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse 
deb http://in.archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse 

Save it and You will be able to run

sudo apt update

and install any packages.

KK Patel
  • 18,693
  • 14
  • 57
  • 79
  • while copying the content it says "Read only" ..... it's not saving the changes. – shiv Jun 28 '18 at 18:56
  • Use sudo with command – KK Patel Jun 28 '18 at 19:20
  • yes sir i used. it's get copied successfully. but after running " sudo apt update" it shows this W: GPG error: http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 E: The repository 'http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. – shiv Jun 28 '18 at 19:29
  • sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32. Run and try again. It should work. – KK Patel Jun 28 '18 at 19:32
  • its shows :- Executing: /tmp/apt-key-gpghome.icm5OLsLPH/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 gpg: key 3B4FE6ACC0B21F32: 18 signatures not checked due to missing keys gpg: key 3B4FE6ACC0B21F32: public key "Ubuntu Archive Automatic Signing Key (2012) " imported gpg: Total number processed: 1 gpg: imported: 1 W: Unable to read /etc/apt/apt.conf.d/ - DirectoryExists (2: No such file or directory) W: Unable to read /etc/apt/apt.conf.d/ - DirectoryExists (2: No such file or directory) – shiv Jun 28 '18 at 19:36
  • sudo mkdir /etc/apt/apt.conf.d/ – KK Patel Jun 28 '18 at 19:55
  • the problem is that `sources.list` is not the only file in `/etc/apt/`. There are various other important files and directories there and APT probably will not work without them :( – Zanna Jun 28 '18 at 20:22