42

From inside a Debian docker container running jessie I get

vi blah
bash: vi: command not found

so naturally I reach for my install command

sudo apt-get install vim

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package vim

while searching for some traction I came across these suggestions with various outputs

        cat /etc/apt/sources.list
deb http://deb.debian.org/debian jessie main
deb http://deb.debian.org/debian jessie-updates main
deb http://security.debian.org jessie/updates main

        apt-get install software-properties-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package software-properties-common

        apt-get install python-software-properties
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-software-properties


        apt-get install apt-file
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package apt-file

since this server is the docker container for a mongo image it intentionally is a bare bones Debian installation ... installing vi is just to play about during development

2 Answers 2

93

I found this solution

apt-get update

apt-get install apt-file

apt-file update

apt-get install vim     # now finally this will work !!!

here is a copy N paste version of above

apt-get update && apt-get install apt-file -y && apt-file update && apt-get install vim -y

Alternative approach ... if you simply need to create a new file do this when no editor is available

cat > myfile
(use terminal to copy/paste)
^D
4
  • 3
    Perfect.. just followed these steps blindly.. it worked..
    – raksja
    Mar 10, 2017 at 21:03
  • 1
    last line save my time thanks ... this is for second time ... that this answer helped me Jul 4, 2019 at 15:18
  • 2
    This worked great for me. All I had to do was apt-get update then apt-get install ... Sep 6, 2019 at 15:12
  • 1
    I used that to install vim in a running docker container. Don't ask why :)
    – sr9yar
    May 6, 2021 at 22:23
19

Although Scott Stensland's answer works, you don't need to install software-properties-common and python-software-properties. Running only the following commands is enough.

apt-get update
apt-get install apt-file
apt-file update
apt-get install vim
3
  • this one works for me.. Jun 3, 2017 at 15:12
  • this one works as well and don't install all the things that software-properties-common and python-software-properties will bring. Nov 25, 2017 at 23:09
  • I get a Unable to locate package apt-file with this one :( Jan 30, 2020 at 10:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.