Ubuntu – E: Package ‘apache2’ has no installation candidate on Ubuntu 17.10

Apache2aptpackage-managementserver

Got error E: Package 'apache2' has no installation candidate while installing apache2 with sudo apt-get install apache2 on Ubuntu 17.10.
Here is the message displayed on terminal.

sudo apt-get install apache2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package apache2 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'apache2' has no installation candidate

Message after apt-cache policy apache2 command.

apache2:
  Installed: (none)
  Candidate: (none)
  Version table:

Message after egrep -v '^#|^ *$' /etc/apt/sources.list /etc/apt/sources.list.d/*.list command

/etc/apt/sources.list.d/linuxgndu-ubuntu-sqlitebrowser-artful.list:deb http://ppa.launchpad.net/linuxgndu/sqlitebrowser/ubuntu artful main
/etc/apt/sources.list.d/mongodb-org-3.6.list:deb [arch=amd64,arm64] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse
/etc/apt/sources.list.d/slack.list:deb https://packagecloud.io/slacktechnologies/slack/debian/ jessie main
/etc/apt/sources.list.d/sublime-text.list:deb https://download.sublimetext.com/ apt/stable/
/etc/apt/sources.list.d/vscode.list:deb [arch=amd64] http://packages.microsoft.com/repos/vscode stable main
/etc/apt/sources.list.d/webupd8team-ubuntu-java-artful.list:deb http://ppa.launchpad.net/webupd8team/java/ubuntu artful main

How can I solve this issue?

Screen shot of error while installing apache2

Best Answer

The main problem is missed /etc/apt/sources.list. You can recreate it with:

cat <<EOF | sudo tee /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu $(lsb_release -cs) main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu $(lsb_release -cs)-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu $(lsb_release -cs)-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu $(lsb_release -cs)-backports main universe restricted multiverse
EOF

Then run

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install apache2
Related Question