I wanted to ask a likely very simple question regarding Linux (AlmaLinux-9.2)...
I unpacked the file and I wanted to execute the binary file nerdctl
. However, I could not do it if I did not add ./
at the beginning of the command?
It is because I need to move or link up this file to another folder /usr/local/bin
, so it can be globally used.
But, how can I execute the file without adding ./
?
In Linux, the reason you need to use
./
before executing a binary in the current directory is related to thePATH
environment variable. ThePATH
variable tells the shell which directories to search for executable files.The
./
before a command indicates to the shell to look in the current directory for the executable. By default, the current directory (.
) is usually not part of thePATH
for security reasons. If it were, malicious binaries could be disguised with common command names in directories, and you could inadvertently run them.If you want to run the
nerdctl
command from any location without prefixing with./
, you have a few options:Move or Symlink to a Directory in
$PATH
: Most system-wide binaries are stored in directories that are included in thePATH
variable, such as/usr/local/bin
,/usr/bin
, etc. If you move or symlink your binary to one of these directories, you can call it from anywhere without the./
prefix.OR
Modify the
PATH
Variable: This is less recommended because it can introduce the security issues mentioned above, but you could add the directory containingnerdctl
to thePATH
variable.Add this to your
~/.bashrc
or~/.zshrc
(depending on your shell):