How To Set Path In Bash Shell Linux?
Linux bash shell provides a lot of information into running applications.
PATH is one of the most important one which is used to locate binary files and libraries. In some situations we may need to edit, add or remote some paths and locations from bash PATH variable. In this tutorial we will different use cases about these operations.
Print Current PATH Variable
We will start printing current
PATH variable. This will print currently available paths in the
$ echo $PATH
PATH Variable Syntax
As we can see in previous example paths are stored in single line and delimited with
: . Each entry is a separate path to search binaries and libraries.
Add New Path
Now we need to add new path to the
PATH variable. We will put a delimiter which is
: and than put the new path we want to add. In this example we will add
/home/ismail/bin as new path.
Remove Existing Path
In order to remove existing path we should copy the PATH variable value and then remove the path we want to remove. Then set new PATH variable.
Export PATH Variable
Newly created PATH variable will be available for the current shell sessions. If we need to made this available for all other sessions we should export PATH variable to all other sessions with
export command like below.
$ export PATH
Make PATH Variable Persistent
Even we export our PATH variable this will not made our variable persistent after a reboot all newly added paths will be removed. In order to make PATH variable persistent we should add it to
.bashrc file which will read before a shell start for the current user.
Make PATH Variable Persistent and Available For All Users
In previous example the PATH variable will be available for only current user. If we need to make it available for all other system users we should change the system wide file
/etc/profile with text editor. In order to change
profilefile we need root privileges.