Add your custom path to $PATH environment variables in Linux
Background
An environment variable is a dynamic value that affects the way running processes will behave in a computer.
They were introduced in their modern form in 1979 with Version 7 Unix, so are included in all Unix operating system flavors and variants from that point onward including Linux and macOS. From PC DOS 2.0 in 1982, all succeeding Microsoft operating systems including Microsoft Windows, and OS/2 also have included them as a feature, although with somewhat different syntax, usage and standard variable names. [1]
Typical use cases
Adding custom $PATH
variable is essential to run your own custom command (not provided by the operating system itself), few of the application may be:
- Invoking custom tool (like
GO
executables and other tools in development environment) - Getting custom modifications to your UNIX like environments (e.g. Linux, POSIX, etc.)
Some codeworks
The variables can be used in both command line and scripts, usually referred by putting $
symbol in front or around the variable name. For example, (in Bourne shell): [1]
echo $PATH # prints out the $PATH variables
Assignment
In Unix, the following commands are used to set the environment variables:
export VARIABLE # For Bourne and related shell
This command makes the variable available for the interactive shell itself. For example:
export $PATH
Environment variables in Bourne shell (like BASH) are assigned using =
operator in between variable name and the value itself, as:
VARIABLE = value
For example:
$PATH = $PATH:$HOME/Programs/go/tools/
Making environment variable available outside of the active shell
For this, you should manually enter the modifications you desire to make with environment variables in ~/.bash_profile
.
Consider not using ~/.bashrc
for this purpose unless you are a beginner. Putting the modification in ~/.bashrc
will make the path available only as the BASH operates itself.]
This command can be helpful for importing edited shell configuration files :
source FILENAME # e.g. source ~/.bash_profile