Adding a Directory to Linux PATH Environment Variable

During custom compiling of applications, sometimes you will see error messages like the following:

make: depmod: Command not found

That doesn’t necessarily mean your computer doesn’t have something installed, but it could mean the program just couldn’t find it.
Here is how to fix it:

First thing is to find the program in question “depmod”, run:

locate depmod

The first command should update the file location database, and the second should find it.

According to my results:

[root@localhost]# locate depmod

it’s at “/sbin/depmod”

If it doesn’t show up, you probably don’t have the correct package installed, you should find the package and install it via yum or apt-get

Assuming it’s installed, we need to let the compiling program know where to find it.

To do that simply run (changing /sbin to whatever folder you found the app in above):

export PATH

We now added /sbin to the path, so now when the compiling program tries to run depmod, it will automatically run /sbin/depmod

However, this will be cleared after your session is over.
If you want the modified PATH variable to persist to other sessions/reboots, you will need to add those lines to a file:

For a Single User:

vim $HOME/.bash_profile
#to include the folders you want to add

For the root user, it is the same as a Single User except edit the file:

vim /root/.bash_profile

For All Users except root

vim /etc/profile
#at the end of the file add:

Making changes to those files will require a logout/login or reboot to take effect. So in the meantime you could just run:

export PATH

 You can do this with other folders as well.
For Example,
I use it for directories I store my scripts in. So instead of running,
“/home/user/scripts/myscript” everytime I want to run that script
I can just run
 Just by adding /home/user/scripts to my PATH


One thought on “Adding a Directory to Linux PATH Environment Variable

Comments are closed.