Add directory to PATH variable CentOS and Red Hat

When we running a command in Linux, logically we should type the full path to that command. For example, since the pwd command is in the /bin directory, we should actually type the /bin/pwd command to list files in the current directory. With the benefit of the PATH, an environment variable, that’s not required. The bash shell automatically searches through the directories listed in a user’s PATH for the command that user just typed at the command line. Environment variables are constant from console to console.

To determine the PATH for the current user account, run the echo $PATH command. You should see a series of directories in the output. The differences between the PATH for a regular user and one for a root user have narrowed in RHEL 6 and CentOS 6:

$ echo $PATH


# echo $PATH

The PATH is determined globally by current settings in the /etc/profile file.
The PATH for individual users can be customized with an appropriate entry in
that user’s home directory, in the hidden file named .profile.

In this example we will add /home/myscripts directory to path, so we can execute our shell scripts from there.

export PATH