48

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

101

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
(you can now type into this file or just copy/paste)
^D  #  to exit edit session

now you have a new file myfile

4
  • 4
    Perfect.. just followed these steps blindly.. it worked..
    – raksja
    Commented Mar 10, 2017 at 21:03
  • 1
    last line save my time thanks ... this is for second time ... that this answer helped me Commented 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 ... Commented Sep 6, 2019 at 15:12
  • 1
    I used that to install vim in a running docker container. Don't ask why :)
    – sr9yar
    Commented May 6, 2021 at 22:23
21

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
4
  • this one works for me.. Commented 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. Commented Nov 25, 2017 at 23:09
  • 4
    I get a Unable to locate package apt-file with this one :( Commented Jan 30, 2020 at 10:02
  • Small improvement for the second line try apt-get install apt-file -y to skip the y/n prompt, and also apt-get install vim -y for the fourth line.
    – dss
    Commented Dec 12, 2022 at 5:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .