How To Set Path In Bash Shell Linux? – POFTUT

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 ones which is used to locate binary files and libraries. In some situations, we may need to edit, add or remove some paths and locations from the bash PATH variable. In this tutorial, we will differently use cases about these operations.

Print Current PATH Variable

We will start printing the current PATH variable. This will print currently available paths in the PATH variable.

Print Current PATH Variable

Print Current PATH Variable

PATH Variable Syntax

As we can see in previous example paths are stored in a single line and delimited with : . Each entry is a separate path to search binaries and libraries.

Add New Path

Now we need to add a new path to the PATH variable. We will put a delimiter which is : and then put the new path we want to add. In this example, we will add /home/ismail/bin as new path.

Add New Path

Add New Path

Remove Existing Path

In order to remove the existing path, we should copy the PATH variable value and then remove the path we want to remove. Then set the new PATH variable.

Export PATH Variable

Newly created PATH variable will be available for the current shell sessions. If we need to make this available for all other sessions we should export PATH variable to all other sessions with  export command like below.

LEARN MORE  How To Set, Get and Change Bash Environment Variable?

Make PATH Variable Persistent

Even we export our PATH variable this will not make our variable persistent after a reboot all newly added paths will be removed. In order to make the 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

Make PATH Variable Persistent

Make PATH Variable Persistent and Available For All Users

In the previous example, the PATH variable will be available for only the current user. If we need to make it available for all other system users we should change the system-wide file /etc/profile with a text editor. In order to change profilefile, we need root privileges.

Make PATH Variable Persistent and Available For All Users

Make PATH Variable Persistent and Available For All Users

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)