THe PATH
is defined at different levels of the system. Processes and subshells inherit the setting from the parent shell. So if you export
a path in the terminal, the change will be valid in the current shell and any subshell of that terminal.
While you can add a custom path for every executable you want to place everywhere on your system, this approach will quickly become unwieldy. You would need to add a directory to the PATH for any other application you install. It would limit the portability of your program.
Before we indicate how the PATH can be changed at a higher level, I would suggest considering other, better approaches.
Place your executable in one of the default paths
Instead, stuck to the conventional approach for your custom applications, just like Ubuntu maintainers stick to some conversions when configuring applications that come with the system.
For your custom applications, that means: install them anywhere you want. Then install an executable in one of the directories mentioned in the PATH.
For your custom programs, /usr/local/bin
is the appropriate conventional places to put your executable. If you need the executable to be available on a per user basis, place the executable in ~/.local/bin
instead. Leave /usr/bin
to the management of the system software management.
The executable can be a binary, a symbolic link to the executable installed elsewhere, or a wrapper script.
Coding the path in your executable
Instead of relying on a non standard systemwide PATH setting in your program, define custom PATHS in your executable itself where to find resources. To make this portable, work with a base directory, i.e., the directory where the program is installed, and locate your resources in a directory structure underneath. At runtime, the executable can determine the path where it resides. Put that path in a variable, e.g. RUN_PATH, then locate your resources using a relative path, e.g. images under $RUN_PATHS/icons, etc.
Change the systemwide PATH
If you insist doing it your way, feel free. It is your system. This is a way to change the PATH variable early in the boot process. As explained before, this approach is difficult and unelegant to port. If everybody decided to work your way, it would lead to a large PATH with custom entries on user's system. A long path slows down finding and executing any executable on the system.