41

Windows 10 Ubuntu bash failing to install packages. Whenever I try install new package with below command, getting same error.

root@VASI-HOME-PC:/mnt/c/Users/vadap# apt-get install atom
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package atom

This is not just with atom pacakge but i tried installing other packages like pip as well and received same error.

Devoloper250
  • 1,361
  • 2
  • 10
  • 11
  • 1
    The error message you received, indicates Atom is required, which means the package you are trying to install has a GUI. That isn't going to be supported by WSl out of the box. In other words, you are not going to be able to install any package, that requires Atom. – Ramhound Sep 19 '18 at 19:25
  • @Ramhound I have tried to install pip and few other packages. I have received the same error. Does it mean all of them had GUI ? – Devoloper250 Sep 20 '18 at 15:59
  • I'm having this issue on WSL2 Debian 10, trying to install `openssh-server` as root user. I think the issue the OP had was that he was invoking `apt` as the root user, and not sudoing from an unprivileged user. I'm not sure why, but `apt` only works when you run it with sudo from a non-root user... – Willman Aug 26 '20 at 02:08

7 Answers7

60

Executed below 2 commands and then I was able to install the packages.

sudo apt update    
sudo apt install python3-pip

Source - https://linuxize.com/post/how-to-install-pip-on-ubuntu-18.04/

MMM
  • 2,652
  • 5
  • 25
  • 43
Devoloper250
  • 1,361
  • 2
  • 10
  • 11
  • 1
    This answer is unlikely to be well recieved, unless you provide the relevant information from the link, like what you actually did in the body of the answer. – Ramhound Sep 20 '18 at 18:24
  • Thank you @Ramhound . I have updated the steps executed and later I was able to install the packages like pip. – Devoloper250 Sep 20 '18 at 18:37
  • 4
    After `update` do `apt upgrade` to be updated. – Timo Oct 02 '20 at 19:03
  • 1
    I just `sudo apt update` followed by `sudo apt upgrade` like Timo said and that was enough for me to get it to work. – Eyal Gerber Jul 03 '22 at 14:43
  • 1
    Current wording suggests you need `python3-pip`, but you don't - running `sudo apt update` is enough. – Alexander Revo May 07 '23 at 16:48
9

System: Windows 10 Enterprise, Ubuntu Windows Subsystem for Linux.

I ran this command:

sudo apt-get install dos2unix

I had this error:

E: Unable to locate package dos2unix

I then ran:

sudo apt-get update

and then:

sudo apt-get install dos2unix

and it installed properly.

ProtoHumanCam
  • 91
  • 1
  • 2
4

This fixed it perfectly for me: https://sundarnarasiman.net/2021/05/15/wsl2-apt-update-not-working/

Reposting incase the link ever dies:

Step #1.

On the Ubuntu distro, create a file at this location /etc/wsl.conf.

The file should have the following configuration.

[network]
generateResolvConf = false

If we don’t set this file, WSL will automatically load a default /etc/resolv.conf with default namesever configuration.

Shut down and restart the distro.

Step #2

Delete the default /etc/resolv.conf file.

sudo rm /etc/resolv.conf

Create a new /etc/resolv.conf with the following entry.

nameserver 8.8.8.8

Now, restart the WSL2 and open the distro again. The apt update on WSL2 should work like a charm.

0

Same error, solved after:

sudo vi /etc/apt/sources.list # add source
sudo apt update # update source cache

My sources.list file:

deb http://mirrors.163.com/ubuntu/ bionic main restricted
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted
deb http://mirrors.163.com/ubuntu/ bionic universe
deb http://mirrors.163.com/ubuntu/ bionic-updates universe
deb http://mirrors.163.com/ubuntu/ bionic multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ bionic-security main restricted
deb http://security.ubuntu.com/ubuntu/ bionic-security universe
deb http://security.ubuntu.com/ubuntu/ bionic-security multiverse

Edit this list according to your location, as some sources may not apply globally.

Qinsi
  • 111
  • 4
0

What was working for me:

wsl --set-version Ubuntu-18.04 2

or

wsl --set-version Ubuntu-20.04 2
ZygD
  • 2,459
  • 12
  • 26
  • 43
-1

Easiest solution for Non GUI packages installation in a fresh WSL

Just run the below commands in the terminal:

sudo apt-get update

sudo apt-get install your-package-name

The error is generally observed when you have a fresh WSL configuration on windows. Thus, you need to update your apt-get package manager. However, as mentioned above, for packages that involve a GUI (Atom), it isnt supported by WSL out of the box.

-2

Usually only updates packages is needed before:

sudo apt update
TOUDIdel
  • 97
  • 1