I have a compiled program in a certain folder that I would like to access from anywhere without needing the write ./path/to/file/each/time/app_name
. For example, the app executable is installed in this ./path/to/file/each/time/app_name
path, and I would like to be able to open it by writing app_name
in the command line, and nothing more than that. How could I do that?
Asked
Active
Viewed 47 times
1

pdaranda661
- 13
2 Answers
1
Create a script (as root) called /usr/local/bin/app_name
and put this inside it:
#!/bin/bash
/path/to/file/app_name $@
Then make the script executable:
sudo chmod +x /usr/local/bin/app_name

Kristopher Ives
- 5,509
0
Create an alias for your program in the .bashrc
file.
nano ~/.bashrc
At the end of the file type the line:
alias app_name=/path/to/file/each/time/app_name
Then save (CTRL+O then Enter) and exit (CTRL+X).
You will be able to use the alias in new Terminal windows you open.

Alejandro
- 695
/usr/local/bin
. In addition, it is worthwhile mentioning the option to use ~/bin or ~/.local/bin if only the current user needs access - in that case, no root access is needed. – vanadium Sep 10 '21 at 11:19~/.bin
and such are not in$PATH
by default so that's a deeper rabbit hole. There are other problems with symlinks. This solution works everywhere regardless of those problems and also allows you to do more flexible things like add default arguments or run more complex composite commands. – Kristopher Ives Sep 11 '21 at 12:35/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
– Kristopher Ives Sep 14 '21 at 12:24$PATH
values, see https://askubuntu.com/questions/386629/what-are-the-default-path-values – Kristopher Ives Sep 14 '21 at 14:10~/bin
is added to PATH if and only if it exists (as vanadium says). You can find the code that adds it in~/.profile
– Zanna Sep 14 '21 at 14:50