How to run my C program from anywhere within the System (Ubuntu 10.10)?
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? Bye. |
Put that modified PATH line in /etc/environment
More on the subject https://help.ubuntu.com/community/En...nt%20variables |
I tried 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. The contents of .bashrc file:
Code:
# ~/.bashrc: executed by bash(1) for non-login shells. |
found it. put the "export PATH=$PATH:/home/ahuq/MappingServer/md5_program" line in:
/etc/bash.bashrc and problem solved! |
Thanks @ DarkVenger ......... :)
|
Hi -
Glad you got it working. And changing /etc/bash.bashrc is definitely the way to go to modify the $PATH for all users. However, "/home/ahuq/.bashrc" and "/home/ahuq/.profile" should have worked, too. It didn't look like you had any syntax errors, and there shouldn't be any "special place" you needed to put your changes. You shouldn't have to restart the system ... but you *should* log out from and log back in to your entire GUI session. Or, equivalently, log in from another "virtual terminal" (e.g. <Ctl-Alt-F1>. Either way, it should have read your modified local environment and given you the new $PATH. |
You could have put it in your ~/.profile file, and exported it. Not exporting PATH is why it didn't work originally. Using .profile or .bash_login (which ever one you use) is better than .bashrc because .bashrc will be run again whenever you create a subshell, adding the same directory to your PATH variable for each subshell. The .profile script will be sourced once when you log in.
For programs and scripts you do yourself, you can also put them in $HOME/bin/ which should be in $PATH already instead of changing a system directory or file. |
@ anis_huq
Edit post #3 to use [code]code goes here[/code] tags. And use code tags from now on whenever posting code or command output. |
@mtk358 -
Didn't your mommy ever teach you the importance of using words like "Please" and "Thank you"? ;) |
All times are GMT -5. The time now is 04:25 AM. |