4

I downloaded VS Code's .deb file for Ubuntu. I renamed it to vs.deb.

Then I go to my downloads directory:

cd ~/Downloads

And now that I'm here, I try to install it:

sudo apt install vs.deb

And here's what I get:

Reading package lists... Done   
Building dependency tree          
Reading state information... Done   
E: Unable to locate package vs.deb   
E: Couldn't find any package by glob 'vs.deb'

But when I install it using ./vs.deb, then it gets installed:

sudo apt install ./vs.deb

Why doesn't Linux accept the name of the file inside the same directory without requiring the relative path?

Zanna
  • 70,465
Saeed Neamati
  • 793
  • 2
  • 7
  • 20
  • 2
    Is the current directory defined in any PATH statement? I think not therefore you need the ./ This is well known and not a stupid behavior. – David Aug 26 '21 at 09:41
  • 8
    Does this answer your question? How do I install a .deb file via the command line? Quoting from Braiam's answer: "Even if you are on the directory with the package you need to give a path using ./ at the start" – Kulfy Aug 26 '21 at 09:50
  • 2
    You are trying to install a file; so a path is required. Your command without a path is to download & install the package name you provided (it's more secure to not make assumptions that it could be a file but be a package in an approved source). – guiverc Aug 26 '21 at 09:54
  • 1
    @David: If you're talking about the PATH environment variable, e.g. /usr/local/bin:/bin:... then no, it would make no sense for apt to search $PATH for .deb files given as args. The querent made a wrong assumption about the shell being relevant. Your comment might be misleading to beginners who don't realize that it doesn't actually apply; I'd suggest deleting it. – Peter Cordes Aug 27 '21 at 04:46

1 Answers1

20

What you experience is not related to the shell, but to how the apt command interprets the arguments on the command line.

It is primarily aimed at installing packages from the software repositories. By default, an argument to apt means the name of a package in the software sources. The message:

E: Unable to locate package vs.deb

clearly indicates that a package vs.deb does not exist in the software sources.

Still, apt allows you to directly install a downloaded .deb package file and resolve dependencies for it. You must give an explicit file path to indicate you want to install a .deb file. ./vs.deb already indicates a file path: ./ means the current directory, so apt will find the vs.deb file in the current directory.

Actually, it is never the shell that "finds" a file. The shell just passes arguments to the application, and it is up to the application to interpret these arguments. At most, the shell does expansion (e.g. replacing * with all filenames or ~ with the full path of your home folder) or variable substitution (e.g. $HOME is replaced by the content of that variable).

vanadium
  • 88,010
  • Arguably, brace expansion does qualify as "finding" the files. – chrylis -cautiouslyoptimistic- Aug 27 '21 at 03:06
  • 2
    apt's predecessor, apt-get, could never take a .deb as a command line option, only a package name; you had to use dpkg -i to install a .deb file. So there's historical precedent for Debian's higher-level package tools to not interpret args as paths, at least not by default. – Peter Cordes Aug 27 '21 at 04:43
  • @chrylis-cautiouslyoptimistic- Brace expansion doesn't do anything related to files, it's a purely textual transformation. Wildcard expansion, on the other hand, does look for matching files. – Barmar Aug 27 '21 at 14:09