4

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

Organic Marble
  • 23,641
  • 15
  • 70
  • 122

4 Answers4

9

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
N0rbert
  • 99,918
  • A note for future internet searchers who may come across this answer: if you're using a version other than 17.10, replace "artful" with your version's name (rather than copy/pasting the whole thing directly into your terminal as I did.) – Ilak Jul 20 '20 at 02:30
  • @Ilak thanks for idea, I edited the answer to make it universal. – N0rbert Jul 20 '20 at 05:37
2

Try sudo apt-get update and then sudo apt-get install apache2. I recommend installing the complete LAMP Stack using tasksel

sudo apt-get install tasksel

sudo tasksel to launch it Select LAMP server and install it. Hope that helps.

N0rbert
  • 99,918
1

This might be the fastest

  1. Run sudo software-properties-gtk
  2. Under 'Ubuntu Software' tab select/tick the first 4 options- main, universe, restricted, multiverse
  3. Click 'Close'
  4. Click 'Reload'

Now, try your install command again.

0

follow step by step below.

1.Open your sources list by Terminal then key in "sudo nano /etc/apt/sources.list"

    sudo nano /etc/apt/sources.list

2.copy and past under your list.by this code .Pls put the "#" in font of your old code list.

    deb http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi
deb http://archive.raspbian.org/raspbian/ bullseye main contrib non- free rpi

deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi

deb http://archive.raspberrypi.org/debian/ buster main contrib non-free rpi

deb http://archive.raspberrypi.org/debian/ buster main

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

3.ctrl x and then y then enter "on your keyboard"

4.sudo systemctl status apache2 you will get "Unit apache2.service could not be found."

    sudo systemctl status apache2

5.sudo apt update && sudo apt upgrade -y

    sudo apt update && sudo apt upgrade -y

6.sudo systemctl status apache2

    sudo systemctl status apache2

7.sudo apt install apache2 -y

    sudo apt install apache2 -y

8.hostname -I

    hostname -I

9.go to your web browser and address is " Localhost "

done .