Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Friends, I want to add my C program's path to the environment variable PATH. My C program called "md5". So that I can execute it from anywhere (i.e any directory).

My md5 program is located at /home/ahuq/MappingServer/md5_program. So what I did was to put:

export PATH=$PATH:/home/ahuq/MappingServer/md5_program

in the running shell. This only makes temporary changes and lets me run the md5 program from anywhere temporarily.

root@ahuq-kitchen:/home/ahuq# md5 -sanis
MD5 ("anis") = 38a1ffb5ccad9612d3d28d99488ca94b

But I want to make this change permanent.

I tried to put the line PATH=$PATH:/home/ahuq/MappingServer/md5_program at the end of /home/ahuq/.bashrc and /home/ahuq/.profile files. I logged out of the shell and went in again. But it didn't work:

root@ahuq-kitchen:/home/ahuq# md5 -sanis
No command 'md5' found, did you mean:
Command 'cd5' from package 'cd5' (universe)
Command 'mdu' from package 'mtools' (main)
Command 'mdb' from package 'mono-debugger' (universe)
md5: command not found

Maybe I am putting the PATH statement in the wrong place of the above mentioned files. There are a lot if-else-fi structures inside those two files. Do I need to put the PATH statement inside any of those structures? Do I just logout or do I have to restart the system to make the changes active?

share|improve this question
It seems like your .bashrc and .profile files aren't running. If you do source ~/.bashrc or source ~/.profile, does the path get fixed? –  Shawn J. Goff May 1 '11 at 1:21
add comment

migrated from stackoverflow.com May 1 '11 at 0:13

This question came from our site for professional and enthusiast programmers.

4 Answers

It seems like you're putting the path in the correct place. It might not work if you have spaces somewhere in the path however. You can try doing this for correctness:

export PATH="$PATH:/home/ahuq/MappingServer/md5_program"

Alternatively, just put the app inside /usr/local/bin. Or even install the md5sum package, which seems to do the same thing as your app.

share|improve this answer
add comment

Without seeing your dotfiles, it's hard to say for sure, but from what you quoted, you left out the "export" when you added it to the .profile and .bashrc files.

share|improve this answer
Nope. I tried that. Putting in: "export PATH=$PATH:/home/ahuq/MappingServer/md5_program" at the end of "/home/ahuq/.bashrc" and "/home/ahuq/.profile" files do not help. –  Anonymous May 1 '11 at 0:07
Just to be sure - you also need to either log out and back in after adding export or you need to manually source the files from the command line by source ~/.bashrc –  Shawn J. Goff May 1 '11 at 1:29
add comment

From your question:

root@ahuq-kitchen:/home/ahuq# md5 -sanis

But, you say you only edited the .bashrc for your user.

If you need the new path to be global for every user, you could edit /etc/bash.bashrc (this could cause issues, if other users cannot execute md5 from your homedir due to permissions issues). Or, if you only need the change to also apply to root as well as your local user, consider edited /root/.bashrc as well.

Alternatively and more preferred, as root, you could consider installing/copying the md5 command to /usr/local/bin, which is my default in everyone's $PATH in Ubuntu.

You could do this with:

$ sudo cp /home/ahuq/MappingServer/md5_program/md5 /usr/local/bin
$ sudo chown root:root /usr/local/bin/md5
$ sudo chmod 755 /usr/local/bin/md5

share|improve this answer
add comment

Are you sure that you are running bash (and not some other Bourne shell flavour such as sh) ? Try ps $$ and echo $SHELL to verify that.

Also, you could put statements such as echo IN FILE XYZ directly before adding this to the path to see whether your path settings are actually executed.

And put the adding of your path as close to the end of your shell startup file as possible. I've seen startup files in the past where at some point the entire PATH is reset and rebuild from scratch instead of appending new directories

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.